I currently have several movie clips and buttons on the stage that do different things. I have one button, that "Attacks" the enemy player and decreases his HP. This button has an event listener for a click, and when that is activated it goes through an IF statement and changes his health bar etc based on how low his health is. When the health reaches 0 I want to transition the entire screen to another ending screen.
I tried using .visible to make all of my other objects go invisible and that worked, however setting the instance button that I click to attack as not visible will not work. I have also tried removeChild, which won't remove the button, and gotoAndPlay/Stop to a future frame gives me a null object reference.
Here's the code for that specific button at that frame.
stop();
OSButton.addEventListener(MouseEvent.CLICK, OSAttack);
function OSAttack(event:MouseEvent):void
{
var health1:int = parseInt(RegHealth.text);
health1 = health1 - 1000;
if(health1 == 9000 || health1 == 8000 || health1 == 7000 || health1 == 6000 || health1 == 5000
|| health1 == 4000 || health1 == 3000 || health1 == 2000 || health1 == 1000 || health1 ==0){
REGHPBAR.play();
}
RegHealth.text = health1.toString();
if(health1 <= 0){
////// WHAT CODE DO I PUT HERE?
}
}
visible
orremoveChild
should work. If removing the object from the display list gives anull
reference exception on a later frame, it must have been removed. – Jason Sturges