Note that there are some explanatory texts on larger screens.

plurals
  1. POClearing eventListeners on a FileReference object
    primarykey
    data
    text
    <p>I have a strange issue! I am trying to remove an event listener on a FileReference object by calling a function, but it seems not to be removed, and I do not understand why.</p> <p>Here is the code:</p> <pre><code>private function clearFileUploadListeners(file:FileReference, index:String):void { var dispatchEvent:Function = function(event:Event):void { dispatch(event.type, event, index); }; file.removeEventListener(Event.COMPLETE, dispatchEvent); var bool:Boolean = file.hasEventListener(Event.COMPLETE); if (bool) trace("ERROR"); } </code></pre> <p>When I run this code, the trace actually happens. I don't understand why this boolean returns true, when I just tried to remove the eventListener just above! I guess I am probably doing something really stupid because it seems like a strange error.</p> <p>I hope someone can please help me on this issue.</p> <p>EDIT:</p> <p>I believe it has to do with the fact that the dispatchEvent function is defined inside another function when I add the listener:</p> <pre><code>private function upload(file:FileReference, index:String):void { var dispatchEvent:Function = function(event:Event):void { dispatch(event.type, event, index); }; file.addEventListener(Event.COMPLETE, dispatchEvent); } </code></pre> <p>The problem is that I need to access this "index" variable from the listener, and I can't set it as a global variable as each file has it's own index and it's a burden if I have to extend each event class to keep track of the index (Event, ProgressEvent, ..). I hope someone can please help me on this.</p> <p>EDIT2:</p> <p>I actually found a temporary solution, I am not sure if it is the best! I put my removeListener method actually inside the upload method, but made it a variable. As AS3 allows dynamic object, I attached this method to one of my object, and so I just call the reference to the method when necessary. The event is actually removed. Is this a good solution please?</p> <p>Thank you very much, Rudy</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload