JSFL: fl.addEventListener() & fl.removeEventListener()

I’ve been experimenting with the Flash CS5 JSFL API lately and ran across these handy methods adding and removing event listeners to the fl object. However, I discovered that the functionality has changed from what the documentation states. After digging around the internet for some answers with no luck, I finally contacted Adobe about it and sure enough here is what they say.

fl.addEventListener now returns an eventID (valid across FLA files for that Flash session) when you add an event listener. When you remove the event listener, you have to specify the event type and the event id.

Example for adding:
var evtID = fl.addEventListener("documentChanged", docChangedHandler);

Example for removing:
fl.removeEventListener("documentChanged", evtID);

This affects Flash CS4 & Flash CS5. Hopefully this clears things up for people and hopefully the documentation will be updated soon. After experimenting with it while attempting to prevent duplicate event listeners from being added when working with a windowswf that has been opened and closed repeatedly, now you can derive a way to persist the id’s and keep your panel from adding duplicate listeners. Pretty handy I must say.


    Thanks for this, had me scratching my head for a while. I’ve added a comment to the docs page for CS5 (comments are closed on CS4 unfortunately) for addEventListener and removeEventListener in case anyone ends up there.

      No problem, I received word that they are updating the doc’s soon if they haven’t already.

      • by bschmidtke
      • 8:45 pm, February 4, 2011
      • Reply

Leave a Reply