你可以让一个类来封装你的逻辑,例如,从调用函数访问的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