查看下一个代码,告诉我您希望打印什么。然后运行它并检查实际发生的情况。
package
{
import flash.display.Sprite;
import flash.events.Event;
public class TestFlashEvents extends Sprite
{
private static const DUMMY_EVENT:String = "DummyEvent";
private var dummyObjects:Vector.<DummyObject> = new Vector.<DummyObject>(100);
public function TestFlashEvents()
{
for(var i:int = 0; i < dummyObjects.length; i++){
dummyObjects[i] = new DummyObject(this);
addEventListener(DUMMY_EVENT, dummyObjects[i].listener);
}
removeEventListener(DUMMY_EVENT, dummyObjects[41].listener);
dispatchEvent(new Event(DUMMY_EVENT));
}
private var counter:int = 0;
public function onGettingEvent(dummyObject:DummyObject):void{
if(counter == 25){
for(var i:int = 0; i < 50; i++){
removeEventListener(DUMMY_EVENT, dummyObjects[i].listener);
trace("Removing", dummyObjects[i].id);
}
}
trace("Handeling event", counter, dummyObject.id);
counter++;
}
}
}
import flash.events.Event;
class DummyObject
{
private static var dummyObjectsCounter:int = 0;
public var id:String;
private var tester:TestFlashEvents;
public function DummyObject(tester:TestFlashEvents)
{
this.tester = tester;
id = "DummyObject " + dummyObjectsCounter;
dummyObjectsCounter++;
}
public function listener(event:Event):void{
tester.onGettingEvent(this);
}
}
该removeEventListener
功能实际上不起作用。告诉我你怎么看。我还在adobe中打开了一个错误。