2014-03-01 23 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應該有效。