This content has been marked as final. Show 7 replies
the listener function should be defined before the the load() method is applied.
for any specific help, is this as2 or as3?
Yes, sorry, I should've mentioned -- I'm referring to AS3.
But for example, look at these docs: http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Liv eDocs_Parts&file=00000132.html
Is that example actually bad practice?
no, that's ok.
it's the load() method that shouldn't be applied until the listener function is defined and a listener is attached to the url loader. but it doesn't matter if the listener is attached before or after the listener function is defined.
the flash compiler compiles named functions before other code so the listener function is registered by the compiler before the addEventListener code even if the coding is reversed in your as or fla file.
OK, that's what I thought...
But in the case of the XML example, what other way is there to do this? It seems like the URLLoader object begins loading as soon as it's constructed... is it a better idea to go
myLoader = new URLLoader(myXMLURL);
or would the writing of a new object into that variable overwrite any 'listener' connections in it? (If that's how that works?)
loading doesn't start until the load() method is called.
According to the docs, it starts immediately if you supply the URLRequest object as an argument in the constructor.
Is the idea that if you want to attach a listener, you should never supply that argument, but instead do it with .load() ? (If so, should they update the docs?)
yes, you're correct. i didn't realize that.
it appears you can add listener, checking for "complete", much later than the load initialization. in testing on my system i was able to add the listener up to 100 ms after loading started and still have the listener detect a load complete event.