views:

434

answers:

3

I have an SWF loading in an SWF containing a papervision scene.

I've done it before yet problem is, I get an error - I'm not sure what the issue really is.

    private function downloadSWF(url:String):void
  {
   trace(url);
   var urlRequest:URLRequest = new URLRequest(url);
   var loader:Loader = new Loader(); 
   loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loaderProgressEventHandler);
   loader.load(urlRequest);
  }



 private function loaderProgressEventHandler(ev:ProgressEvent):void
  {

   loader.preloaderCircle.percent = ev.bytesLoaded / ev.bytesTotal;
  }

When the application runs the code - I get the error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
 at com.dehash.pv3d.examples.physics::WowDemo()

Why am I getting this if the loading hasn't even complete yet?

Thanks in advance guys.


Edit: Try a blank child swf, see if the other one was trying access something in the parent. – Jorge

I did this, it seems, even with a simple SWF with a mouse click listener causes the Error:

TypeError: Error #1009: Cannot access a property or method of a null object reference. at simple_fla::MainTimeline/frame1()

My code for that is:

import flash.events.MouseEvent;

this.stage.addEventListener(MouseEvent.CLICK, onClick);

function onClick(ev:MouseEvent):void
{
    trace("MouseClick");
}

Am I missing something blatantly obvious??

A: 

It won't even load if there's an error. You're accessing an unreferenced object on the WowDemo() class...did you instantiate correctly the class?

Jorge
Aye, I think so - The SWF I'm loading runs fine on its own. The parent SWF runs ok too, just when I try to load the child SWF, thats when this error pops up. Is it possible the child SWF is trying to use a library from the parent?
Glycerine
As an additional, it all works when I don't try and load an external SWF with papervision.
Glycerine
Try a blank child swf, see if the other one was trying access something in the parent.
Jorge
A: 

this seems to work inside my child SWF:

this.addEventListener(Event.ADDED_TO_STAGE, addedToStageEventHandler);

function onClick(ev:MouseEvent):void
{
    trace("MouseClick");
    var event:Event = new Event("END", true, false);
    this.dispatchEvent(event);
}

function addedToStageEventHandler(ev:Event):void
{
    this.stage.addEventListener(MouseEvent.CLICK, onClick);

}

does anyone know Why?

Glycerine
A: 

The problem is that the loaded swf starts running without it being added to the stage. So stage is null, resulting in that error.

The second example with the addedToStageEventHandler works because there stage is only referenced after the object was added to the stage, so stage is not null anymore.

A possible solution for the first error is adding the loader to the stage. That way, when the swf is loaded and starts, it already has a stage reference.

frankhermes
Thank you dude. Makes so much sense now.
Glycerine