# Changing variables when on a different frame

**URL:** <https://forum.kirupa.com/t/changing-variables-when-on-a-different-frame/291742>\
**Category:** Uncategorized\
**Created:** [July 4, 2009, 11:40am UTC](https://forum.kirupa.com/t/changing-variables-when-on-a-different-frame/291742 "2009-07-04T11:40:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lan0011](https://avatars.discourse-cdn.com/v4/letter/l/df705f/32.png) [@lan0011](https://forum.kirupa.com/u/lan0011)\
**Post date:** [July 4, 2009, 11:40am UTC](https://forum.kirupa.com/t/changing-variables-when-on-a-different-frame/291742/1 "2009-07-04T11:40:23Z")

</div>

OK this might take a wile to explain but ill give it a go.  
I’m trying to make a sort f upgrade menu for my Flash game (AS2)  
but I’m a bit stuck. Ok my char has got this action script on it.

onClipEvent(load){  
\_global.speed = 1  
}

onClipEvent (enterFrame) {  
if (Key.isDown(Key.RIGHT)) {  
this.gotoAndStop(2);  
this.\_x += speed;  
this.\_rotation = 90;  
} else if (Key.isDown(Key.LEFT)) {  
this.gotoAndStop(4);  
this.\_x -= speed;  
this.\_rotation = 270;  
}  
if (Key.isDown(Key.UP)) {  
this.gotoAndStop(1);  
this.\_y -= speed;  
this.\_rotation = 0;  
}  
if (Key.isDown(Key.DOWN)) {  
this.gotoAndStop(3);  
this.\_y += speed;  
this.\_rotation = 180;

}  
}

That all works fine but what i want to do is make it that when you click a button the var speed will change. I can do that quite easily with this code

on(press){  
\_global.speed += 1  
}

and that works fine two but what i want to do is have the button for upgrading the speed on a different frame (ie. the upgrade menu)

So on frame 1 is the moving char and there is a button linking frame 1 to frame 2 (upgrade menu) and on that frame it has the button for upgrading the var speed and then a button linking frame 2 back to one but it doesn’t work. I think i no why because on the char is says onClipEvent(load){ \_global.speed = 1 }

so that means that the var speed will revert back to 1 when you go back to the first frame.

if any one knows away around this problem could you please post a reply.

thank:)
