Actionscript 3 - List error when loading another a swf in my swf

你说的曾经没有我的故事 提交于 2019-12-02 14:32:40

问题


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()

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;
    }

Adding it:

addChild(m_homePage as DisplayObject);

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.


回答1:


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%"/>

And load 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;
}

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



来源:https://stackoverflow.com/questions/23304899/actionscript-3-list-error-when-loading-another-a-swf-in-my-swf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!