actionscript 3 - AS3 Global Variables -


ok have managed once before cannot remember how or find source found then. making simple flash game. there several characters moving. make each level more difficult other have decided alter movement speed of each character level level. if declare , assign values these variables on main timeline in frame 1 doesn't work way want it. when go level 2, in frame, speed goes should. when go next level, level 1 higher movement speed, value assignment processed again, means movement speed goes scratch.

//frame 1 var speed:int = 5; //level accomplished, speed++, goto frame 2  //frame 2 //level accomplished, speed++, goto frame 1 

and code on frame 1 runs again, setting value of "speed" 5.

i have tried putting variable in class, problem still same, everytime goes frame 1 code "var speed:speed = new speed();" runs again , value of variable goes whatever assigned in speed.as file.

i have tried many different combinations make global variables inside package outside class globally accessible without creating new object.

here current code:

//speed.as package { public var speed:int = 5; }  //game.fla import speed;  trace(speed); 

this throws error "access of possibly undefined property speed..."

as said, have tried many different combinations , got lot of different errors, been googling , digging 8-9 hours , it's driving me crazy. guys last hope, grateful answer telling me how use global variables (i know global variables bad, seen lot of people writing though don't know why), if there easy , better solution please tell, don't want rewrite entire code or make compatible other solution. know global variables solve problem me, don't know how use them.

i need instructions on in both .as file , .fla file. in advance!

does cycle between frame 1 , 2? if does, use functions instead. don't need .fla.

//declare variables var speed:int = 5;  //in case use button transit frame. edit code wish. btnlevel1.addeventlistener(mouseevent.click, level1);  private function level1(e:mouseevent):void { movieclip(root).gotoandstop(2); speed++; //your other code level goes here  btnlevel2.addeventlistener(mouseevent.click, level2); }  private function level2(e:mouseevent):void { movieclip(root).gotoandstop(3); speed++; //again, other code goes here  btnlevel1.addeventlistener(mouseevent.click, level1); } 

should work, think.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -