在flash cs3中,监听事件,比如:
**.addEventListener(Event.COMPLETE,hander);
function hander(event:Event):void
很多时候要向这个hander方法里传递参数。使程序更灵活。
下面有一个简单的方法:
**.addEventListener(Event.ENTER_FRAME,function(e:Event){ hander2(e,12,6); });//比如要传“12”“6”这个参数
hander2如下:
function hander2(event:Event,i:int,j:int):void {
if ((event.target as MovieClip).currentFrame == i) {
event.target.gotoAndPlay(j);
}
}
问题就解决了
还有,我在实际中有这么一个应用:
package {
class Test extends Spire {
public function tell() {
var timer:Timer = new Timer(1000,1);
timer.addEventListener(TimerEvent.Timer, function(event:Event) {
this.dispatchEvent(new Event("time_out"));
});
timer.start();
}
}
}
这样就报错了,
TypeError: Error #1006: dispatchEvent is not a function. at MethodInfo-160()
然后我做了一些修改,将this.dispatchEvent()改成parent.dispatchEvent()
OK,错误就解决了。
当然你也可以把this.dispatchEvent()用一个直接的方法封装,然后timer直接回调那个方法,这也是我们经常使用的方式之一。
所以注意了,在内function里,this已经不是代指class了,而是变为外层的function。
关于GC回收的问题,请参考:http://blog.csdn.net/dengxingbo/archive/2010/02/02/5279624.aspx