This is another very weird problem, it's a dialog in a play flow that's supposed to disappear after the player makes a choice with one of its buttons, but it's not disappearing no matter what I try.
What is particularly odd is that none of the associated code has changed in at least 18 months, including where it's called from, and it was working fine until a couple days ago with commits that all had to do with the ship objects, not the dialogs.
And there is one and only one place this dialog is called from - one of the first things I wondered is whether I was getting multiple instances of this dialog being created somehow but no, not that I see.
When the player clicks on one of the fire buttons we calculate the combat results and display them both in the broadside results screen but also on the enemy ship's info screen. If the player cancels, we're supposed to clear the screen.
On the broadside results dialog, we just have the Close button, which calls the same function as the broadside confirm dialog cancel button to clear the screen.
Here is the Broadside Results Dialog view, player has hit one of the fire buttons, damage calculated and applied. At this point the Broadside Confirm dialog is supposed to already be gone, but it's not- it's hiding under the results dialog.
Here's the first version of that "clear map" code which worked fine until a few days ago:
//clears game map of dialogs and resets ships to deselected states, called from several places
function clearGameMap(eventTarget:Object) {
//clear selected state on all ships, remove ship info screen, broadside confirm and broadside results dialogs
for (var i: int = 0; i < shipListSide1.length; i++) {
//clear all selected states and return to default unselected background graphic
shipListSide1[i].selected = false;
shipListSide1[i].combatSelected = false;
//selection borders
var borderChild = shipListSide1[i].getChildByName("shipBorder");
borderChild.visible = false;
var borderChildCombat = shipListSide1[i].getChildByName("borderCombat");
borderChildCombat.visible = false;
//show default counter background, build label name, leave surrendered ships to sleep peacefully
if (!shipListSide1[i].isSurrendered) {
shipListSide1[i].gotoAndStop(shipListSide1[i].country+"_def");
}
}
//clear selected states side2
for (var i: int = 0; i < shipListSide2.length; i++) {
//clear all selected states and return to default unselected background graphic
shipListSide2[i].selected = false;
shipListSide2[i].combatSelected = false;
//selection borders
var borderChild = shipListSide2[i].getChildByName("shipBorder");
borderChild.visible = false;
var borderChildCombat2 = shipListSide2[i].getChildByName("borderCombat");
borderChildCombat2.visible = false;
//show default counter background, build label name, leave surrendered ships to sleep peacefully
if (!shipListSide2[i].isSurrendered) {
shipListSide2[i].gotoAndStop(shipListSide2[i].country+"_def");
}
}
//in this one case we're transitioning from broadside confirm dialog to broadside results dialog and we DON'T want to remove the info screens
if (("broadsideFireButtonHull" != eventTarget.name) && ("broadsideFireButtonRigging" != eventTarget.name)) {
//remove ship info screen
if (currShipInfo.parent) {
removeChild(currShipInfo);
}
//remove ship target info screen
if (currShipInfo_combat.parent) {
removeChild(currShipInfo_combat);
}
}
//remove broadside confirm dialog
if (broadsideConfirmDialog.parent) {
removeChild(broadsideConfirmDialog);
}
//remove broadside results dialog
if (broadsideResultsDialog.parent) {
removeChild(broadsideResultsDialog);
}
}
However it stopped working, this is what I get now:
I check the variable at that point and indeed its parent is now null, but it's still being displayed on screen. Or at least I don't see another instance.
So I made some efforts to make it go away:
//remove broadside confirm dialog
if (broadsideConfirmDialog.parent) {
broadsideConfirmDialog.parent.setChildIndex(broadsideConfirmDialog, broadsideConfirmDialog.parent.getChildIndex(broadsideConfirmDialog) - 1);
broadsideConfirmDialog.visible = false;
broadsideConfirmDialog.alpha = 0;
var fireHullButton = broadsideConfirmDialog.getChildByName("broadsideFireButtonHull");
var fireRiggingButton = broadsideConfirmDialog.getChildByName("broadsideFireButtonRigging");
var broadside_CancelButton = broadsideConfirmDialog.getChildByName("broadsideCancelButton");
fireHullButton.removeEventListener(MouseEvent.CLICK, fireButtonHandler);
fireHullButton.removeEventListener(MouseEvent.ROLL_OVER, broadsideButtonRollOverHandler);
fireHullButton.removeEventListener(MouseEvent.ROLL_OUT, broadsideButtonRollOutHandler);
fireRiggingButton.removeEventListener(MouseEvent.CLICK, fireButtonHandler);
fireRiggingButton.removeEventListener(MouseEvent.ROLL_OVER, broadsideButtonRollOverHandler);
fireRiggingButton.removeEventListener(MouseEvent.ROLL_OUT, broadsideButtonRollOutHandler);
broadside_CancelButton.removeEventListener(MouseEvent.CLICK, cancelButtonHandler);
broadside_CancelButton.removeEventListener(MouseEvent.ROLL_OVER, broadsideButtonRollOverHandler);
broadside_CancelButton.removeEventListener(MouseEvent.ROLL_OUT, broadsideButtonRollOutHandler);
removeChild(broadsideConfirmDialog);
}
Removed event listeners, tried to push it back in z order, invisible, alpha 0, but none of it works, it is a terminator dialog. But ALL of this code executes with zero errors. Again, I don't see another instance and I also don't see how a second instance could exist, but those damned buttons are still doing their rollovers after I supposedly successfully removed the required event listener.
Here is the code that creates the Broadside Confirm and Broadside Results dialogs and the event listeners/handlers, none of which has changed in many months. The results dialog goes away with no issues when told to:
function createBroadsideConfirmDialog(firingShip, targetShip, initialHitTable, hitTable, modSternRake, modRakeValue, modCrewQuality, modInitialBroadside, modShotType, modAnchored, modCrewLosses, finalGuns, targetRange) {
//only display if ship can fire to this side
if ((targetObj.targetStarboard && targetObj.firingShip.loadedRight) || (false == targetObj.targetStarboard && targetObj.firingShip.loadedLeft)) {
broadsideConfirmDialog = new Broadside_Confirm_Dialog();
broadsideConfirmDialog.x = 430;
broadsideConfirmDialog.y = 117;
addChild(broadsideConfirmDialog);
//firing and target ship name fields
var broadsideShipNameFont = new ShipNameFont();
var textBroadsideShipNameFormat: TextFormat = new TextFormat();
textBroadsideShipNameFormat.size = 16;
textBroadsideShipNameFormat.font = broadsideShipNameFont.fontName;
textBroadsideShipNameFire.defaultTextFormat = textBroadsideShipNameFormat;
textBroadsideShipNameFire.width = 200;
textBroadsideShipNameFire.height = 16;
textBroadsideShipNameFire.x = 55;
textBroadsideShipNameFire.y = 15;
textBroadsideShipNameFire.embedFonts = true;
textBroadsideShipNameFire.textColor = 0xFFFFFF;
textBroadsideShipNameFire.htmlText = "<p align='center'>" + firingShip.name + "</p>";
broadsideConfirmDialog.addChild(textBroadsideShipNameFire);
textBroadsideShipNameTarget.defaultTextFormat = textBroadsideShipNameFormat;
textBroadsideShipNameTarget.width = 200;
textBroadsideShipNameTarget.height = 16;
textBroadsideShipNameTarget.x = 55;
textBroadsideShipNameTarget.y = 71;
textBroadsideShipNameTarget.embedFonts = true;
textBroadsideShipNameTarget.textColor = 0xFFFFFF;
textBroadsideShipNameTarget.htmlText = "<p align='center'>" + targetShip.name + "</p>";
broadsideConfirmDialog.addChild(textBroadsideShipNameTarget);
//gun and range fields
var broadsideConfirmFields = new Arial();
var textBroadsideGunsFormat: TextFormat = new TextFormat();
textBroadsideGunsFormat.size = 16;
textBroadsideGunsFormat.font = broadsideConfirmFields.fontName;
var textBroadsideGuns: TextField = new TextField();
textBroadsideGuns.defaultTextFormat = textBroadsideGunsFormat;
textBroadsideGuns.width = 80;
textBroadsideGuns.height = 30;
textBroadsideGuns.x = 167;
textBroadsideGuns.y = 186;
textBroadsideGuns.embedFonts = true;
textBroadsideGuns.textColor = 0xFFCC00;
textBroadsideGuns.htmlText = "<p align='left'>" + finalGuns + "</p>";
broadsideConfirmDialog.addChild(textBroadsideGuns);
var textBroadsideRange: TextField = new TextField();
textBroadsideRange.defaultTextFormat = textBroadsideGunsFormat;
textBroadsideRange.width = 80;
textBroadsideRange.height = 30;
textBroadsideRange.x = 67;
textBroadsideRange.y = 186;
textBroadsideRange.embedFonts = true;
textBroadsideRange.textColor = 0xFFCC00;
textBroadsideRange.htmlText = "<p align='left'>" + targetRange + "</p>";
broadsideConfirmDialog.addChild(textBroadsideRange);
//initial and final hit table fields
textBroadsideHitTableFormat.size = 22;
textBroadsideHitTableFormat.font = broadsideConfirmFields.fontName;
var textBroadsideHitTable: TextField = new TextField();
textBroadsideHitTable.defaultTextFormat = textBroadsideHitTableFormat;
textBroadsideHitTable.width = 80;
textBroadsideHitTable.height = 30;
textBroadsideHitTable.x = 235;
textBroadsideHitTable.y = 185;
textBroadsideHitTable.embedFonts = true;
textBroadsideHitTable.textColor = 0xFFCC00;
textBroadsideHitTable.htmlText = "<p align='left'>" + initialHitTable + "</p>";
broadsideConfirmDialog.addChild(textBroadsideHitTable);
var textBroadsideFinalHitTable: TextField = new TextField();
textBroadsideFinalHitTable.defaultTextFormat = textBroadsideHitTableFormat;
textBroadsideFinalHitTable.name = "textBroadsideFinalHitTable";
textBroadsideFinalHitTable.width = 80;
textBroadsideFinalHitTable.height = 30;
textBroadsideFinalHitTable.x = 235;
textBroadsideFinalHitTable.y = 325;
textBroadsideFinalHitTable.embedFonts = true;
textBroadsideFinalHitTable.textColor = 0xFFCC00;
textBroadsideFinalHitTable.htmlText = "<p align='left'>" + hitTable + "</p>";
broadsideConfirmDialog.addChild(textBroadsideFinalHitTable);
//modifier fields
var textBroadsideModifiersFormat: TextFormat = new TextFormat();
textBroadsideModifiersFormat.size = 13;
textBroadsideModifiersFormat.font = broadsideConfirmFields.fontName;
var textBroadsideModCrew: TextField = new TextField();
textBroadsideModCrew.defaultTextFormat = textBroadsideModifiersFormat;
textBroadsideModCrew.width = 80;
textBroadsideModCrew.height = 30;
textBroadsideModCrew.x = 232;
textBroadsideModCrew.y = 214;
textBroadsideModCrew.embedFonts = true;
textBroadsideModCrew.textColor = 0xFFDD8C;
textBroadsideModCrew.htmlText = "<p align='left'>" + modCrewQuality + "</p>";
if ("0" == modCrewQuality) {
textBroadsideModCrew.htmlText = "<p align='left'>--</p>";
textBroadsideModCrew.x = 238;
textBroadsideModCrew.textColor = 0x999999;
}
broadsideConfirmDialog.addChild(textBroadsideModCrew);
var textBroadsideModAmmo: TextField = new TextField();
textBroadsideModAmmo.defaultTextFormat = textBroadsideModifiersFormat;
textBroadsideModAmmo.width = 80;
textBroadsideModAmmo.height = 30;
textBroadsideModAmmo.x = 232;
textBroadsideModAmmo.y = 233;
textBroadsideModAmmo.embedFonts = true;
textBroadsideModAmmo.textColor = 0xFFDD8C;
textBroadsideModAmmo.htmlText = "<p align='left'>" + modShotType + "</p>";
if ("0" == modShotType) {
textBroadsideModAmmo.htmlText = "<p align='left'>--</p>";
textBroadsideModAmmo.x = 238;
textBroadsideModAmmo.textColor = 0x999999;
}
broadsideConfirmDialog.addChild(textBroadsideModAmmo);
var textBroadsideModRake: TextField = new TextField();
textBroadsideModRake.defaultTextFormat = textBroadsideModifiersFormat;
textBroadsideModRake.width = 80;
textBroadsideModRake.height = 30;
textBroadsideModRake.x = 232;
textBroadsideModRake.y = 251;
textBroadsideModRake.embedFonts = true;
textBroadsideModRake.textColor = 0xFFDD8C;
textBroadsideModRake.htmlText = "<p align='left'>" + modRakeValue + "</p>";
if ("0" == modRakeValue) {
textBroadsideModRake.htmlText = "<p align='left'>--</p>";
textBroadsideModRake.x = 238;
textBroadsideModRake.y = 249;
textBroadsideModRake.textColor = 0x999999;
}
broadsideConfirmDialog.addChild(textBroadsideModRake);
var textBroadsideModSternRake: TextField = new TextField();
textBroadsideModSternRake.defaultTextFormat = textBroadsideModifiersFormat;
textBroadsideModSternRake.width = 80;
textBroadsideModSternRake.height = 30;
textBroadsideModSternRake.x = 232;
textBroadsideModSternRake.y = 269;
textBroadsideModSternRake.embedFonts = true;
textBroadsideModSternRake.textColor = 0xFFDD8C;
textBroadsideModSternRake.htmlText = "<p align='left'>" + modSternRake + "</p>";
if ("0" == modSternRake) {
textBroadsideModSternRake.htmlText = "<p align='left'>--</p>";
textBroadsideModSternRake.x = 238;
textBroadsideModSternRake.y = 267;
textBroadsideModSternRake.textColor = 0x999999;
}
broadsideConfirmDialog.addChild(textBroadsideModSternRake);
var textBroadsideModInitBroad: TextField = new TextField();
textBroadsideModInitBroad.defaultTextFormat = textBroadsideModifiersFormat;
textBroadsideModInitBroad.width = 80;
textBroadsideModInitBroad.height = 30;
textBroadsideModInitBroad.x = 232;
textBroadsideModInitBroad.y = 287;
textBroadsideModInitBroad.embedFonts = true;
textBroadsideModInitBroad.textColor = 0xFFDD8C;
textBroadsideModInitBroad.htmlText = "<p align='left'>" + modInitialBroadside + "</p>";
if ("0" == modInitialBroadside) {
textBroadsideModInitBroad.htmlText = "<p align='left'>--</p>";
textBroadsideModInitBroad.x = 238;
textBroadsideModInitBroad.y = 285;
textBroadsideModInitBroad.textColor = 0x999999;
}
broadsideConfirmDialog.addChild(textBroadsideModInitBroad);
var textBroadsideModCrewLosses: TextField = new TextField();
textBroadsideModCrewLosses.defaultTextFormat = textBroadsideModifiersFormat;
textBroadsideModCrewLosses.width = 80;
textBroadsideModCrewLosses.height = 30;
textBroadsideModCrewLosses.x = 234;
textBroadsideModCrewLosses.y = 304;
textBroadsideModCrewLosses.embedFonts = true;
textBroadsideModCrewLosses.textColor = 0xFFDD8C;
textBroadsideModCrewLosses.htmlText = "<p align='left'>" + modCrewLosses + "</p>";
if ("0" == modCrewLosses) {
textBroadsideModCrewLosses.htmlText = "<p align='left'>--</p>";
textBroadsideModCrewLosses.x = 238;
textBroadsideModCrewLosses.y = 303;
textBroadsideModCrewLosses.textColor = 0x999999;
}
broadsideConfirmDialog.addChild(textBroadsideModCrewLosses);
//fire and cancel buttons
var broadsideFireButtonHull: Broadside_Confirm_Btn_Fire_Hull = new Broadside_Confirm_Btn_Fire_Hull();
broadsideFireButtonHull.gotoAndStop('default');
broadsideFireButtonHull.x = 208;
broadsideFireButtonHull.y = 372;
broadsideFireButtonHull.name = "broadsideFireButtonHull";
broadsideFireButtonHull.buttonMode = true;
broadsideFireButtonHull.useHandCursor = true;
broadsideFireButtonHull.addEventListener(MouseEvent.CLICK, fireButtonHandler);
broadsideFireButtonHull.addEventListener(MouseEvent.ROLL_OVER, broadsideButtonRollOverHandler);
broadsideFireButtonHull.addEventListener(MouseEvent.ROLL_OUT, broadsideButtonRollOutHandler);
broadsideConfirmDialog.addChild(broadsideFireButtonHull);
var broadsideFireButtonRigging: Broadside_Confirm_Btn_Fire_Rigging = new Broadside_Confirm_Btn_Fire_Rigging();
broadsideFireButtonRigging.gotoAndStop('default');
broadsideFireButtonRigging.x = 99;
broadsideFireButtonRigging.y = 372;
broadsideFireButtonRigging.name = "broadsideFireButtonRigging";
broadsideFireButtonRigging.buttonMode = true;
broadsideFireButtonRigging.useHandCursor = true;
broadsideFireButtonRigging.addEventListener(MouseEvent.CLICK, fireButtonHandler);
broadsideFireButtonRigging.addEventListener(MouseEvent.ROLL_OVER, broadsideButtonRollOverHandler);
broadsideFireButtonRigging.addEventListener(MouseEvent.ROLL_OUT, broadsideButtonRollOutHandler);
broadsideConfirmDialog.addChild(broadsideFireButtonRigging);
var broadsideCancelButton: Broadside_Confirm_Btn_Cancel = new Broadside_Confirm_Btn_Cancel();
broadsideCancelButton.gotoAndStop('default');
broadsideCancelButton.x = 12;
broadsideCancelButton.y = 372;
broadsideCancelButton.name = "broadsideCancelButton";
broadsideCancelButton.buttonMode = true;
broadsideCancelButton.useHandCursor = true;
broadsideCancelButton.addEventListener(MouseEvent.CLICK, cancelButtonHandler);
broadsideCancelButton.addEventListener(MouseEvent.ROLL_OVER, broadsideButtonRollOverHandler);
broadsideCancelButton.addEventListener(MouseEvent.ROLL_OUT, broadsideButtonRollOutHandler);
broadsideConfirmDialog.addChild(broadsideCancelButton);
}
}
function createBroadsideResultsDialog() {
//left offset for damage squares
const BROADSIDE_RESULTS_LEFT_OFFSET = 150;
const INFO_SQUARE_SIZE = 13;
////remove the broadside confirm dialog
//if (broadsideConfirmDialog.parent) {
// broadsideConfirmDialog.parent.removeChild(broadsideConfirmDialog);
//}
//instance broadside results dialog
broadsideResultsDialog = new Broadside_Results_Dialog();
broadsideResultsDialog.x = 430;
broadsideResultsDialog.y = 117;
addChild(broadsideResultsDialog);
//firing and target ship name fields
broadsideResultsDialog.addChild(textBroadsideShipNameFire);
broadsideResultsDialog.addChild(textBroadsideShipNameTarget);
//initial and final hit table fields
textBroadsideHitTableFormat.size = 28;
var textBroadsideResultsHitTable: TextField = new TextField();
textBroadsideResultsHitTable.defaultTextFormat = textBroadsideHitTableFormat;
textBroadsideResultsHitTable.width = 80;
textBroadsideResultsHitTable.height = 30;
textBroadsideResultsHitTable.x = 90;
textBroadsideResultsHitTable.y = 192;
textBroadsideResultsHitTable.embedFonts = true;
textBroadsideResultsHitTable.textColor = 0xFFCC00;
textBroadsideResultsHitTable.htmlText = "<p align='left'>" + targetObj.hitTable + "</p>";
broadsideResultsDialog.addChild(textBroadsideResultsHitTable);
var textBroadsideResultsDieRoll: TextField = new TextField();
textBroadsideResultsDieRoll.defaultTextFormat = textBroadsideHitTableFormat;
textBroadsideResultsDieRoll.width = 80;
textBroadsideResultsDieRoll.height = 30;
textBroadsideResultsDieRoll.x = 192;
textBroadsideResultsDieRoll.y = 192;
textBroadsideResultsDieRoll.embedFonts = true;
textBroadsideResultsDieRoll.textColor = 0xFFCC00;
textBroadsideResultsDieRoll.htmlText = "<p align='left'>" + diceRoll + "</p>";
broadsideResultsDialog.addChild(textBroadsideResultsDieRoll);
//add red X squares for ship's hull damage
for (var i: int = 0; i < damageObj.initialDamageHull; i++) {
var xSquareHull = new Ship_Info_SquareX();
xSquareHull.x = (i * INFO_SQUARE_SIZE) + BROADSIDE_RESULTS_LEFT_OFFSET;
xSquareHull.y = 254;
broadsideResultsDialog.addChild(xSquareHull);
}
//add red X squares for ship's gun damage
for (var i: int = 0; i < damageObj.initialDamageGun; i++) {
var xSquareGun = new Ship_Info_SquareX();
xSquareGun.x = (i * INFO_SQUARE_SIZE) + BROADSIDE_RESULTS_LEFT_OFFSET;
xSquareGun.y = 280;
broadsideResultsDialog.addChild(xSquareGun);
}
//add red X squares for ship's rigging damage
for (var i: int = 0; i < damageObj.initialDamageRigging; i++) {
var xSquareRigging = new Ship_Info_SquareX();
xSquareRigging.x = (i * INFO_SQUARE_SIZE) + BROADSIDE_RESULTS_LEFT_OFFSET;
xSquareRigging.y = 306;
broadsideResultsDialog.addChild(xSquareRigging);
}
//add red X squares for ship's crew damage
for (var i: int = 0; i < damageObj.initialDamageCrew; i++) {
var xSquareCrew = new Ship_Info_SquareX();
xSquareCrew.x = (i * INFO_SQUARE_SIZE) + BROADSIDE_RESULTS_LEFT_OFFSET;
xSquareCrew.y = 332;
broadsideResultsDialog.addChild(xSquareCrew);
}
var broadsideResultsCloseButton: WSIM_Broadside_Results_Button_Close = new WSIM_Broadside_Results_Button_Close();
broadsideResultsCloseButton.gotoAndStop('default');
broadsideResultsCloseButton.x = 111;
broadsideResultsCloseButton.y = 372;
broadsideResultsCloseButton.name = "broadsideResultsCloseButton";
broadsideResultsCloseButton.buttonMode = true;
broadsideResultsCloseButton.useHandCursor = true;
broadsideResultsCloseButton.addEventListener(MouseEvent.CLICK, cancelButtonHandler);
broadsideResultsCloseButton.addEventListener(MouseEvent.ROLL_OVER, broadsideButtonRollOverHandler);
broadsideResultsCloseButton.addEventListener(MouseEvent.ROLL_OUT, broadsideButtonRollOutHandler);
broadsideResultsDialog.addChild(broadsideResultsCloseButton);
}
//broadside confirm fire button event handler, initiates calculation and application of damage to target ship
function fireButtonHandler(e: Event) {
//extra insurance we don't shoot when we shouldn't be able to
if ((targetObj.firingShip.loadedRight && targetObj.targetStarboard) || (targetObj.firingShip.loadedLeft && !targetObj.targetStarboard)) {
var broadsideSound: Sound = new Sound_Broadside();
broadsideSound.play();
//calculate damage to target ship, decide if this broadside targeted at hull or rigging
if ("broadsideFireButtonHull" == e.target.name) {
//1 hull, 2 rigging
targetObj.targetArea = 1;
calcGunDamage(1);
}
else {
//target is rigging
targetObj.targetArea = 2;
calcGunDamage(2);
}
}
}
//broadside confirm cancel button, clear map
function cancelButtonHandler(e: Event) {
clearGameMap(e.target);
}
//broadside confirm fire button rollover handler
function broadsideButtonRollOverHandler(e: Event) {
e.target.gotoAndStop('hover');
}
//broadside confirm fire button rollover handler
function broadsideButtonRollOutHandler(e: Event) {
e.target.gotoAndStop('default');
}
Edit 6/10, apparently my reputation is enough now that I can add more screenshots. Have added the previously-missing Broadside Results phase
Aucun commentaire:
Enregistrer un commentaire