AS3 Z-INDEXING电影剪辑

时间:2012-11-10 15:16:19

标签: actionscript-3 z-index

大家好 我在舞台上有2个影片剪辑,实例名称为:green&橙子。 我使用此代码时间轴第1帧,以便点击每个项目:

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();
}

任何人都可以告诉我如何从外部.as文件加载:

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 个答案:

答案 0 :(得分: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);
}