简体   繁体   English

外部SWF加载问题

[英]External SWF Loading problem

I have an SWF loading in an SWF containing a papervision scene. 我在包含papervision场景的SWF中加载了SWF。

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. 编辑: 尝试一个空白的孩子swf,看看另一个是否尝试访问父母的东西。 – Jorge - 乔治

I did this, it seems, even with a simple SWF with a mouse click listener causes the Error: 我做了这个,看来,即使使用带有鼠标点击监听器的简单SWF也会导致错误:

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. 问题是加载的swf开始运行而没有将它添加到舞台上。 So stage is null, resulting in that error. 因此stage为null,导致该错误。

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. 与addedToStageEventHandler第二个例子工程,因为有stage后的对象加入到舞台只引用的,所以stage不是空了。

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. 这样,当swf加载并启动时,它已经有一个stage引用。

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? 您正在访问WowDemo()类上的未引用对象...您是否正确地实例化了该类?

this seems to work inside my child SWF: 这似乎是我的孩子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? 有谁知道为什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM