动作3 - 列出的错误时,在我的SWF加载另一个的SWF我的、加载、错误、动作

2023-09-09 21:25:25 作者:Tenderness(温存)

我工作的一个AS3 / Flash小游戏,我们遇到了一个问题,当我们加载我们的主页SWF到我们的登录SWF后有人成功登录

I am working on a AS3/Flash game and we are running into an issue when we load our home page swf into our login swf after someone successfully logs in.

TypeError: Error #2007: Parameter child must be non-null.
at flash.display::DisplayObjectContainer/addChildAt()
at fl.controls::BaseButton/drawBackground()
at fl.controls::LabelButton/draw()
at fl.controls::Button/draw()
at fl.core::UIComponent/drawNow()
at fl.controls::List/drawList()
at fl.controls::List/draw()
at fl.core::UIComponent/callLaterDispatcher()

我们正在开发在Flash Builder中,导入与名为.swc的艺术品和组件集成到我们的项目。我们加载我们的主页SWF并将其添加为这样的显示对象:

We are developing in Flash Builder, importing a .swc with the artwork and components into our project. We load our homepage swf and add it as a display object like this:

private function LoadComplete(e:Event):void
    {
        //trace("LoadComplete");
        m_loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, LoadProgress);
        m_homePage = e.target.content as DisplayObject;
    }

添加它:

addChild(m_homePage as DisplayObject);

有没有更好的方式来加载一个swf到另一个swf?为什么我们会通过我们的登录SWF加载网页的swf但不是当我们单独调试主页时遇到错误?

Is there a better way to load a swf into another swf? Why would we be getting errors when loading the homepage swf through our login swf but not when we are debugging the home page separately?

任何意见将是非常有益的。

Any advice would be very helpful.

推荐答案

如果您要执行自己的SWF内外部的SWF,你需要使用的SWFLoader

If you want to execute external swf inside your own swf, you'll need to use SWFLoader

<mx:SWFLoader
  id="sfwLoader"
  width="100%"
  height="100%"/>

和负载code:

protected function loadSWF():void
{
    var loader:URLLoader = new URLLoader();
    loader.dataFormat = URLLoaderDataFormat.BINARY;
    loader.addEventListener(Event.COMPLETE, onSWFLoaded);
    loader.load(new URLRequest("app-storage:/myOther.swf")); // sample location
}


protected function onSWFLoaded(e:Event):void
{
    var loader:URLLoader = URLLoader(e.target);
    loader.removeEventListener(Event.COMPLETE, onSWFLoaded);
    var context:LoaderContext = new LoaderContext();
    context.allowLoadBytesCodeExecution = true;
    context.applicationDomain = ApplicationDomain.currentDomain;
    sfwLoader.loaderContext = context;
    sfwLoader.addEventListener(Event.COMPLETE, loadComplete);
    sfwLoader.load(loader.data);
}

protected function loadComplete(completeEvent:Event):void
{
    var swfApplication:* = completeEvent.target.content;
}

这laods任何SWF,所以它的潜在的安全漏洞。商祺提供安全性,你可以检查:的http://mabulous.com/air-applications-that-can-be-updated-without-requiring-admin-rights

This laods any swf, so it's potential security hole. Regards providing security you can examine: http://mabulous.com/air-applications-that-can-be-updated-without-requiring-admin-rights