PanoCube/init() Error

Q&A about the latest versions
Post Reply
cdman52
Posts: 8
Joined: Wed Feb 25, 2009 8:21 pm

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
}
}
User avatar
360Texas
Moderator
Posts: 3684
Joined: Sat Sep 09, 2006 6:06 pm
Location: Fort Worth, Texas USA
Contact:

Hmm this is a Pano2VR forum. I do not use Flex. Maybe someone else can help you.
Dave
Pano2VR Forum Global Moderator
Image
Visit 360texas.com
Firefoxer
Posts: 27
Joined: Wed Sep 17, 2008 3:01 pm

You need to check panorama before first use with ENTER_FRAME evnt like this :

if ((panLoader.content as Object).pano != null) {
//insert your code here
} else {
//repeat check
}
cdman52
Posts: 8
Joined: Wed Feb 25, 2009 8:21 pm

Thanks for the reply but I'm already doing something similar to that.
Several places in the code I'm checking for vr.pano != null and i'm still getting the PanoCube/init() error.

Any other ideas? Or do I need to check it in a different place?
Firefoxer
Posts: 27
Joined: Wed Sep 17, 2008 3:01 pm

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
cdman52
Posts: 8
Joined: Wed Feb 25, 2009 8:21 pm

Firefoxer,
Are you working in flash or flex?
I'm still having problems. It might be because my system has to be dynamic. I can't tell it just one file to show, it has to switch between several.

Thanks.
Firefoxer
Posts: 27
Joined: Wed Sep 17, 2008 3:01 pm

I'm working with Actionscript Project in Flex Builder 3. Yes, with a lot of .as files.
Post Reply