2012-11-10 77 views
1

各位好,你好 我有舞臺上有2個movieclip實例名稱:綠色&橙色。 我使用這個代碼,以時間軸幀1〜提出每個項目點:AS3 Z-INDEXING電影短片

MovieClip.prototype.bringForward = function():void{ 
    var currentDepth = this.parent.getChildIndex(this); 
    if(currentDepth<this.parent.numChildren-1){ 
     this.parent.setChildIndex(this, currentDepth+1); 
    } 
} 


green.addEventListener(MouseEvent.MOUSE_UP, clicked); 
orange.addEventListener(MouseEvent.MOUSE_UP, clicked); 

function clicked(e:MouseEvent){ 
    e.target.bringForward(); 
} 

誰能告訴我如何從一個外部文件。如在此加載此:

package { 


    public class Main { 



     public function Main() { 

     } 



    } 

} 

我嘗試了很多次,但我沒有任何運氣。

我嘗試這樣:

package { 

    import flash.display.Sprite; 
    import flash.events.MouseEvent; 
    import flash.accessibility.AccessibilityProperties; 
    import flash.display.Bitmap; 
    import flash.display.DisplayObject; 
    import flash.display.DisplayObjectContainer; 
    import flash.display.MovieClip; 
    import flash.display.Stage; 
    import flash.events.Event; 
    import flash.events.EventDispatcher; 
    import flash.events.KeyboardEvent; 

    public class Main { 




     public function Main() { 


      addListeners(); 




     } 



MovieClip.prototype.bringForward = private final function():void{ 
    var currentDepth = this.parent.getChildIndex(this); 
    if(currentDepth<this.parent.numChildren-1){ 
     this.parent.setChildIndex(this, currentDepth+1); 
    } 
} 




     private final function addListeners():void 
     { 

      green.addEventListener(MouseEvent.MOUSE_UP, clicked); 
      orange.addEventListener(MouseEvent.MOUSE_UP, clicked); 

     } 





    private final function clicked(e:MouseEvent) 
    { 
    e.target.bringForward(); 
    } 





    } 

} 

回答

1

不要使用原型的東西。做這樣的功能類如下:

private function bringForward(clip:DisplayObject):void{ 
    var currentDepth:int = getChildIndex(clip); 
    ... rest of your swapping logic 
} 

private function clicked(event:MouseEvent){ 
    bringForward(event.target as DisplayObject); 
} 
+0

我試過了,但我得到一個錯誤:類型未找到或不是編譯時常量:DisplayObject。 –

+0

導入flash.display.DisplayObject –

+0

或更改爲(clip:MovieClip),因爲您正在使用影片剪輯(兩者均可使用) –