Skip to main content
Participating Frequently
April 20, 2013
Answered

Variable maintained along the timeline?

  • April 20, 2013
  • 1 reply
  • 654 views

I am creating a game in which the user has to click on objects within the room to pick them up (the buttons are made invisible and then a movie clip of the inventory is made visible) but every time they return to the frame, the button to pick up that object returns. I have tried using boolean variables to make them disappear but I'm not doing it right.

Here is the code I tried to use:
(the blue button is the "inventory" made visible & the pink button is the button that makes the inventory visible)

stop();

var pink_clicked:Boolean = false;
blue_btn.visible=false;

blue1.addEventListener(MouseEvent.CLICK, f2_ClickToGoToAndStopAtFrame);

function f2_ClickToGoToAndStopAtFrame(event:MouseEvent):void
{
gotoAndStop(2);
trace ("next clicked")
}


pink_btn.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_2);

function fl_MouseClickHandler_2(event:MouseEvent):void
{
blue_btn.visible=true;
trace("Pink clicked");
pink_clicked=true;
pink_btn.visible=false;
}

if (pink_clicked == true)
{
pink_btn.visible=false

}

When I return to the first frame from the second the variable is made false again so the pink button is still visible.
Please help!

This topic has been closed for replies.
Correct answer WitchXHunter

it still didn't work- I put it in a different layer and then the same layer but the pink button is still coming up instead of the blue when i return to the frame


hey you have a email? I wanna send you a small prototype I made.

when you declare the variable you check if it's undefined before declaring it. then you put the if else check on that frame.

and on the frame you check the boolean and make them invisible again.

It's easier for you to understand if you see the prototype.

1 reply

WitchXHunter
Inspiring
April 20, 2013

try adding another layer of timeline and extend it from the first to last frame and place your variables there.

EmmmaC954Author
Participating Frequently
April 20, 2013

I tried that but it stops the layers containing the rest of the code and I don't know how to say that the variables are true if the blue is visible (I only know the other way around)

WitchXHunter
Inspiring
April 20, 2013

you mean you want this?

if(blue_btn.visible==true){

pink_clicked=true;

}else{

pink_clicked=false;

}

is other of your frame using the same variable?