PDA

View Full Version : Image component not initialized on first viewstack view


drkstr
05-23-2007, 07:30 AM
Hello,

I have a ViewStack that will either display [0] A TextArea or [1] an Image. On the first selection of an image, I get a null reference to my id pointing to the Image component (view.idDocumentImage is null according to debug output). After I select another image, it will work fine through the duration of the session. Any ideas on the best way to solve?

the view switch-a-ma-bob
//load the document from the server
public function loadDocument( ):void {

//get the file type
var indx:Number = myFileName.lastIndexOf('.');
myFileType = myFileName.substring(indx+1).toLowerCase();

trace('--==loading file type: '+myFileType);

if( myFileType == 'html' ) {

myCurrentView = 0;

var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest(myFileName);
//initialize data loader
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.addEventListener(Event.COMPLETE, handleHTMLDocument );
loader.addEventListener( IOErrorEvent.IO_ERROR , handleIOError);

//request the document text
loader.load(request);
}
//image
else if (myFileType == 'jpg' ||
myFileType == 'jpeg' ||
myFileType == 'png' ||
myFileType == 'gif' ) {

trace('Loading Image');
myCurrentView = 1; //image view

var view = idViewStack.selectedChild;
//[fixme: first view not initialized]
trace(view.idDocumentImage);
view.idDocumentImage.load(myFileName);

}
else { // all other file types (hopefully text)
myCurrentView = 0;

var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest(myFileName);
//initialize data loader
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.addEventListener(Event.COMPLETE, handleTextDocument );
loader.addEventListener( IOErrorEvent.IO_ERROR , handleIOError);

//request the document text
loader.load(request);
}

}

the view:
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" >
<mx:Image id="idDocumentImage" />
</mx:Canvas>


Thanks for your time!
...aaron

dr_zeus
05-23-2007, 05:42 PM
Check out the creationPolicy property. By default, a ViewStack will not create children in pages that aren't visible. This gives your application a slight performance boost, but you can change the creation policy to override it if you wish.

drkstr
05-23-2007, 11:35 PM
Ahhh, bad ass! You've saved me once again.

Thanks Doc!
...aaron