你可以讓一個類來封裝你的邏輯,例如,從調用函數訪問的MovieClip,使用Event對象
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class PlayMovieClip {
// register the mouse over event with whatever MovieClip you want
public static function register(mc:MovieClip):void{
mc.addEventListener(MouseEvent.MOUSE_OVER,mover);
}
// unregister the event when you dont need it anymore
public static function unregister(mc:MovieClip):void{
mc.removeEventListener(MouseEvent.MOUSE_OVER, mover);
}
// the MouseEvent will be throw whenever the mouse pass over the registered MovieClip
// and in the MouseEvent property you have the targeted object
// so use it
public static function mover(e:MouseEvent):void{
// check if we have really a MovieClip
var mc:MovieClip=e.currentTarget as MovieClip;
if (mc!==null) {
// we have a MovieClip so we can run the function play on it
mc.play();
}
}
}
使用的財產:
PlayMovieClip.register(mc1);
...
PlayMovieClip.register(mcX);
並刪除事件:
PlayMovieClip.unregister(mc1);
...
PlayMovieClip.unregister(mcX);
這個答案是正確的,但有點矯枉過正 – Allan 2010-01-15 13:42:45
@Allan這取決於你是否想製作可重複使用的代碼;) – Patrick 2010-01-15 14:00:56