开发者

External SWF Loading problem

开发者 https://www.devze.com 2022-12-27 21:40 出处:网络
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.

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 开发者_C百科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??


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.


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?


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号