2014-03-01 19 views
0

我对敌人的班级有一个公共变量。As3:从影片剪辑类访问公共变量? (从时间轴和班级中)

如何在访问这个变量,让我们说,主类?还是英雄课?还是任何班级?

我知道你可以访问主类变量与_root。 (在定义之后),但是如何访问外部类值?

ALSO:

如何从时间轴访问特定的影片剪辑,这些外部类值?

下面是代码:

在Worker.as,我有

This part of code is part of a continuous ENTER_FRAME loop.. 



     if(isFlying) 
     { 
      if(!faceLeft) 
      { 
       gotoAndStop(8); 
      } 
      if(faceLeft) 
      { 
       gotoAndStop(7); 
      } 

      if(flyingDestination < this.x) 
      { 
       if(this.x > flyingDestination) 
       { 
        this.x -= 3; 
       } 
       else 
       { 
        isFlying = false; 
        _root.mainIsFlying = false; 
       } 
      } 
      else 
      { 
       if(this.x < flyingDestination) 
       { 
        this.x += 3; 
       } 
       else 
       { 
        isFlying = false; 
        _root.mainIsFlying = false; 
       } 
      } 
     } 

if(_root.isPunching) 
     { 
      if(this.hitTestObject(_root.ceo)) 
       { 
        isFlying = true; 

        if(this.x < _root.ceo.x) 
        { 
         flyToTheLeft(); 
        } 
        if(this.x > _root.ceo.x) 
        { 
         flyToTheRight(); 
        } 

       } 
     } 


And these are separate functions, a.k.a not part of the ENTER_FRAME function. 

private function flyToTheLeft():void 
{ 
    flyingDestination = this.x - 100; 
    faceLeft = true; 
} 

private function flyToTheRight():void 
{ 
    flyingDestination = this.x + 100; 
} 

在工人影片剪辑的帧8位于飞动漫。在这种飞动漫,我想,这个飞动漫的最后一帧上的代码这样说:

stop(); 
WORKER.as.isFlying = false; 

^^^^^ 我不知道如何代码。

谢谢

回答

0

如果isFlying变量在WORKER.as定义,要更改所有情况下,您应该将变量定义为public static var isFlying = false的变量,然后可以改变它像这样没有.as扩展名的WORKER.isFlying = false。 如果您希望每个实例更改的变量this.parent.isFlying = false应该有效。