大家好,我在舞台上有 2 个带有实例名称的影片剪辑:绿色和橙色。我正在使用此代码到时间线框架 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();
}
}
}