Hu Yu Xin
Hu Yu Xin

Reputation: 1

Button that only works once in flash actionscript 3.0

I have this collecting item game which u have to collect enough "stars" in order to acess a button. After I clicked the "star" button, it suppose to disappear and never appear again. However, when using this script, although the button disappear once I clicked it, when I returned to the frame after going to another frame, it appeared again! pls help!

    star1.addEventListener(MouseEvent.CLICK,gotstar);

    function gotstar(event:MouseEvent){
stars++;
star1.x = -500;
}

Upvotes: 0

Views: 521

Answers (3)

www0z0k
www0z0k

Reputation: 4434

star1.removeEventListener(MouseEvent.CLICK,gotstar); star1.parent.removeChild(star1);
in the click handler code (gotstar) should help
however posting your .fla file might be useful for better understanding

Upvotes: 0

Simon McArdle
Simon McArdle

Reputation: 893

Are you coding on the frames themselves? If so every time you enter a frame it will run every piece of contained code, even if it has already ran once. A solution to this would be to use a document class to track the progress of the game.

Upvotes: 3

Anıl Canlı
Anıl Canlı

Reputation: 434

you need to remove it from the stage if I understand.

try this instead of star1.x = -500;

stage.removeChild(star1);

Upvotes: 1

Related Questions