Accessibility

TechNote (Archived)

Error when Defining a "Load" Event handler in a Loader Object subclass

Issue


Defining "load" Event Handler inside any Loader Object subclass generates "Error opening URL" error message.

Reason


The addEventListener() method requires two parameters: the name of an event, and a reference to a listener. The listener can be either be an object or a function. If you pass an object, the callback function assigned to the object is invoked in the scope of the object. However, if you pass a function, the function is invoked in the scope of a component instance that callsaddEventListener().

In our case the "load" Event Handler calls theLoader.load() method in addition to thehandleEvent() method. This causes the load function to interpret the eventObj parameter as a string inLoader.load(), so it tries to load the URL, generating the error "Error opening URL."

Ref.(98374).

Solution


There are two approaches to solve this issue:

  • Add the following line to the ActionScript code:
     _global.mx.events.EventDispatcher.exceptions.load = 1 ; 
  • Delegating the scope of the function by adding the following code:
     import mx.utils.Delegate; this.addEventListener("load", mx.utils.Delegate.create(this, handleEvent)); 

Additional Information


See also the Developer Center article Proxying Events with the mx.utils.Delegate Class.

AlertThis content requires Flash

To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.

Download the free Flash Player now!

Get Adobe Flash Player

Creative Commons License

Search Support

Document Details

ID:b4525247

Products Affected:

flash