开发者

change var initialized on root time line from class in as3

hi im new on as3 and its make me so frustated since so many changes from as2. i have problem when i want to change variable value from class file, here is the detail.

on the root timeline frame 2, i initialized var like below

stop();
var gameStat;
gameStat = "stop";

then i attached penguin movie clip to the stage, and i make class file called "penguin.as"

//untuk hero penguin
package {
 import flash.display.MovieClip;
 import flash.events.Event;

 public class pengu开发者_开发问答in extends MovieClip {

  var rootref:Object = root;//mendefinisikan root dengan rootref


  public function penguin() {
   rootref.gameStat = "play";//change var value to play

   addEventListener(Event.ENTER_FRAME,on_enter_frame);//tmbhkn enterFrame function

  }//eof penguin()

  private function on_enter_frame(e:Event) {
   trace(rootref.gameStat);//<- test the variable here
   //trace(this.parent.parent.parent.gameStat);
  }
 }//eof class

}

i trace gameStat var in on_enter_frame function, but it still give me "stop" result not "play". any help how to change the "gameStat" value??


Classes should start with the first letter capitalized. Also why make a reference to root if it can be accessed anyway. You should also trace in the constructor whether you set the value.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜