URLLoader - onComplete - First Load Quirk

By mother | Jul 9, 2009

actionscript3

Wondering if anyone has an incite on this. I have a basic Shell class that I’m using to load in all of my assets including two xml files and one css file. Currently I’m using a single URLLoader to load in the three external files. Through testing (Using FDT Pure in Eclipse 3.3.3, publishing using ‘FDT AS3 Application’) I’m running into an interesting issue. Basically the first file that I try and load, regardless which xml file or css file, my onComplete doesn’t seem to be getting called. But everything runs gravy if I insert this line before beginning my loading:

ActionScript Code:
this._urlLoader.load(new URLRequest(“”));

Here’s some more of the code:

ActionScript Code:
protected function initListeners():void {     this._urlLoader.addEventListener(Event.COMPLETE, this.onComplete);     this._urlLoader.addEventListener(IOErrorEvent.IO_ERROR, this.onError);     this._urlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, this.onError); }

ActionScript Code:
protected function load():void {                 this._state++;                 switch( this.state ) {                         case CONF:             this._urlLoader.load(new URLRequest(“config.xml”));             break;         case UI:             this._urlLoader.load(new URLRequest(“ui.xml”));             break;         case CSS:             this._urlLoader.load(new URLRequest(“styles.css”));             break;     }             }

ActionScript Code:
protected function onComplete(e:Event):void {         trace(“Shell :: onComplete”);    // Does not trace on first call of this._urlLoader.load();                 switch( this.state ) {         case CONF:             DataStatic.data = new XML(URLLoader(e.currentTarget).data);             break;         case UI:             DataStatic.ui = new XML(URLLoader(e.currentTarget).data);             break;         case CSS:             DataStatic.css = new StyleSheet();             DataStatic.css.parseCSS(URLLoader(e.currentTarget).data);             break;      }                 load();             } protected function onError(e:ErrorEvent):void {                 trace(“Shell :: onError : “ + e.text);    // Does not trace on first call of this._urlLoader.load();     load();             }

Calling the initial load on the empty URLRequest solves the problem, I’m more just curious as to what the hell is going on.

Oh, I almost forgot. The real kicker of confusion here is that if you notice the onComplete and onError functions both make the next call to load(); Neither statements trace on the first run of load(), but the process doesn’t stop, load() gets called three times.

Is this similar to loader callbacks not being called locally in AS2? At this point I’m royally confused.

Thanks All.

actionscript3

Please reply at our Forum

Leave a Comment

If you would like to make a comment, please fill out the form below.

Name (required)

Email (required)

Website

Comments

© 2007 ActionScript 3.0