# Using Variables in AS3

**URL:** <https://forum.kirupa.com/t/using-variables-in-as3/304893>\
**Category:** flash\
**Created:** [February 16, 2010, 4:42am UTC](https://forum.kirupa.com/t/using-variables-in-as3/304893 "2010-02-16T04:42:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chimeara](https://avatars.discourse-cdn.com/v4/letter/c/bc8723/32.png) [@Chimeara](https://forum.kirupa.com/u/Chimeara)\
**Post date:** [February 16, 2010, 4:42am UTC](https://forum.kirupa.com/t/using-variables-in-as3/304893/1 "2010-02-16T04:42:25Z")

</div>

I am trying to have my timeline play from different frames, depending what frame it is currently on when the button is pressed.

So Pressing the button 3 times will play:  
A-\>B  
B-\>A  
A-\>B

But instead it plays  
A-\>B  
A-\>B  
B-\>A

after the first A-\>B the variable “varButtonFrame” is set to 2, like it should be. but then is reset to “Undefined”. but after this it works as it should. I assume i must have the “var varButtonFrame:int;” in the wrong place…? but not sure where else i can put it.

This is code in a movieclip within the scene:

```auto
var varButtonFrame:int;

//============Buttons========================
Menu_B_2D.addEventListener(MouseEvent.CLICK, Menu_Trans_2D);

 
function Menu_Trans_2D(event:MouseEvent):void 
{
    //MovieClip(this).gotoAndStop("2");

        trace("start of if" + varButtonFrame);
        ///////////////////////////////////////////////
        if(varButtonFrame!=2)
{
    varButtonFrame = 1;
}

trace("the 2nd is" + varButtonFrame);

///////////////////////////////////////////////////
        
    if(varButtonFrame==1)
    {
        varButtonFrame = 3;
        MovieClip(root).gotoAndPlay("890");

    }
    if(varButtonFrame==2)
    {
        varButtonFrame = 1;
        MovieClip(root).gotoAndPlay("941");
    }
    if(varButtonFrame==3)
    {
        varButtonFrame = 2;
    }
    
    trace(varButtonFrame);
}

```
