Detecting whether content successfully loaded in a UILoader component in Flash using ActionScript 3.0

by Peter deHaan on December 19, 2008

in UILoader

The following example shows how you can detect if content loaded successfully in a UILoader container by listening for the ioError event (using the static IOErrorEvent.IO_ERROR constant).

Full code after the jump.

// ActionScript 3.0
/* Requires:
 * - UILoader component in Flash library
 */
import fl.containers.UILoader;
 
var uiLoader:UILoader = new UILoader();
uiLoader.addEventListener(IOErrorEvent.IO_ERROR, uiLoader_ioError);
uiLoader.source = "http://www.helpexamples.com/flash/images/404.jpg";
addChild(uiLoader);
 
function uiLoader_ioError(evt:IOErrorEvent):void {
    var tf:TextField = new TextField();
    tf.text = evt.text;
    tf.autoSize = TextFieldAutoSize.LEFT;
    tf.width = 300;
    tf.wordWrap = true;
    tf.x = 10;
    tf.y = 10;
    addChild(tf);
}

{ 1 comment… read it below or add one }

1 Michael Fox 02.01.09 at 5:32 pm

The event raised tells if an error occurs and the function it calls is executed outside the function containing the event after this function ends. Unlike a try catch block it offers no ability to handle success.

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Previous post:

Next post: