Every time I load a pano in my flex app I get the following error:
TypeError: Error #1009: Cannot access a property or method of a null object reference. at PanoCube/init()
Does anyone know how to fix this or at least catch it?
Thanks.
Here's my Actionscript code:
/**
* loadWithCuepoints(swf:SWFLoader, cuePoints:Array) Loads a
* swf file onto the screen and places it. This allows us to use
* the media cache and to prevent downloading the same media over
* and over.
*
* @param - swf : SWFLoader
* @param - cuePoints : The cuepoints/links to display
* @return - void
**/
public function loadMedia(swf:SWFLoader, media:Media):void
{
url = media.mediaUsePath + media.media1Path;
loader = new Loader();
urlReq = new URLRequest(url);
vr = new MovieClip();
addEventListener(ResizeEvent.RESIZE, resize);
// call initPanorama every frame
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, initPanorama);
loader.contentLoaderInfo.addEventListener(Event.INIT, initHandler);
try
{
loader.load(urlReq);
}
catch(e:Error)
{
;
}
for(var j:int = 0; j < swfCanvas.rawChildren.numChildren; j++)
{
swfCanvas.rawChildren.removeChildAt(j);
}
swfCanvas.rawChildren.addChild(loader); // add your swf directly to the stage
}//end loadWithCuepoints
/**
* initHandler(event:Event) Casts the loader's content as a
* movie clip
*
* @param - event : The event that triggered this
* @return - void
**/
private function initHandler(event:Event):void
{
vr = MovieClip(loader.content); // cast 'DisplayObject' to 'MovieClip'
vr.isFlash10=false; // Disable Flash 10 rendering if the container is Flash 9
loadingTxt.visible = false;
}
/**
* initPanorama(event:Event) Sets the width and height as well
* as the position of the QTVR
*
* @param - event : The event that triggered this
* @return - void
**/
private function initPanorama(event:Event):void
{
// check if the panorama object is available and initialize it
if ((vr!=null) && (vr.pano!=null))
{
vr.pano.setWindowSize(swfCanvas.width, swfCanvas.height); // resize the window
vr.pano.setWindowPos(swfCanvas.parent.x, swfCanvas.parent.y); // reposition
}
}
/**
* resize(event:ResizeEvent) Invalidates the display
* so that the component will resize itself
*
* @param - event : The event that triggered this
* @return - void
**/
private function resize(event:ResizeEvent):void
{
invalidateDisplayList();
}
private var i:int = 0;
/**
* updateDisplayList(unscaledWidth:Number, unscaledHeight:Number)
* Updates the QTVR's size and position.
*
* @param - event : The event that triggered this
* @return - void
**/
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
if ((vr!=null) && (vr.pano!=null))
{
vr.pano.setWindowSize(swfCanvas.width, swfCanvas.height); // resize the window
vr.pano.setWindowPos(swfCanvas.parent.x, swfCanvas.parent.y); // reposition
}
}
PanoCube/init() Error
I use it only once in my code:
public function loadPan():void {
panLoader = new Loader ();
addChild(panLoader);
panLoader.contentLoaderInfo.addEventListener(Event.INIT,panInitListener);
var urlRequest:URLRequest=new URLRequest(loadPath);
panLoader.load(urlRequest);
}
private function panInitListener(e:Event):void {
panLoader.contentLoaderInfo.removeEventListener(Event.INIT,panInitListener);
addChild(panLoader.content);
addEventListener(Event.ENTER_FRAME,delayedPanoInit);
}
private function delayedPanoInit(event:Event):void {
if ((panLoader.content as Object).pano != null) {
removeEventListener(Event.ENTER_FRAME,delayedPanoInit);
... pano is ready now
}
}
Ouh! I forgot! You need to add it to a display list after loading complete before use. see my example
I got this problem before, Pano needs to see stage. If stage==null you got your error, if pano and all parent clips a added to stage everything is OK. try it
public function loadPan():void {
panLoader = new Loader ();
addChild(panLoader);
panLoader.contentLoaderInfo.addEventListener(Event.INIT,panInitListener);
var urlRequest:URLRequest=new URLRequest(loadPath);
panLoader.load(urlRequest);
}
private function panInitListener(e:Event):void {
panLoader.contentLoaderInfo.removeEventListener(Event.INIT,panInitListener);
addChild(panLoader.content);
addEventListener(Event.ENTER_FRAME,delayedPanoInit);
}
private function delayedPanoInit(event:Event):void {
if ((panLoader.content as Object).pano != null) {
removeEventListener(Event.ENTER_FRAME,delayedPanoInit);
... pano is ready now
}
}
Ouh! I forgot! You need to add it to a display list after loading complete before use. see my example
I got this problem before, Pano needs to see stage. If stage==null you got your error, if pano and all parent clips a added to stage everything is OK. try it