No Complete Event for Internal Content

Both Flash & Flex have a Loader component to load content into. It’s nice in Flash because it abstracts sizing & loading code. It’s even cooler in Flex because you can bind to contentPath.

However, if the content you are loading in Flash is an internal symbol, or embedded content in Flex (same thing), you will not get a “complete” event.

I find this wrong since expectations are, “I load content, I get an event while it’s loading, ‘progress’, and I get an event when it is completed, ‘completed’.” However, you only get these events for external content, like external JPEG’s & SWF’s. The documentation for both Flash & Flex versions does not state anything to the contrary.

Frankly, since this component abstracts the loading process, it should be up to the component omit events regardless of loaded content, or emit different events. This now requires the user of the component to know which content type they are loading.

This is an important distinction, because such low level details of whether something is an internal asset are not easily determined at runtime in both Flash & Flex. The more OOP something is, the less you know about where an asset came from. Simply adding the “Embed” metatag in Flex above an asset path, and it’s internal; your code doesn’t change.

Additionally, Flex abstracts control via binding. Since this connection is handled for you, one assumes (wrongly) that those bindings work without data inspection intervention.

What I’ve been doing is just checking if the asset I’m loading has a prefix of “__Resources” in it; if so, it’s an internal asset in Flex, and thus I must immediately call my complete event myself. Hack.

2 Replies to “No Complete Event for Internal Content”

  1. Still a bit of a hack, but …
    var r = this.attachMovie(resource,’test_mc’,1);
    if (r == undefined)
    // doesn’t exist as resource, must be external.

    If the resource is internal it will be attached. If the attachMovie fails, the MovieClipLoader method will be called and then events can be handled normally. You could trigger the onLoadComplete if the attachMovie is successful, or extend MovieClipLoader to include this as the new loadClip method.

    Just a thought.

  2. Thanks Derek!

    mx.core.UIObject & mx.core.ExternalContent do just what you showed; which is a good and solid way to test.

    However, Loader is a component, already coded & released in Flash MX 2004 & Flex; hoping it’ll get fixed and/or replaced in the next version of components for both products.

    Secondly, Flex abstracts this via binding making you go through a go-between which again points the finger of blame at Loader for being ‘too abstracted’.

Comments are closed.