Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Variable maintained along the timeline?

New Here ,
Apr 19, 2013 Apr 19, 2013

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!

TOPICS
ActionScript
603
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Apr 20, 2013 Apr 20, 2013

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.

Translate
Explorer ,
Apr 19, 2013 Apr 19, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 20, 2013 Apr 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)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 20, 2013 Apr 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 20, 2013 Apr 20, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 20, 2013 Apr 20, 2013
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines