如果我正确理解了这个问题,听起来您需要的是构建一个Modular Application。这个想法是您在主应用程序中放置尽可能少的代码/资产,并简单地将其用作其余代码的入口点。我提供的链接应该涵盖所有细节,但这是基本思想:
我的应用程序.mxml
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:s="library://ns.adobe.com/flex/spark">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
protected function login_clickHandler(event:MouseEvent):void
{
trace("login_clickHandler(event)");
this.moduleLoader.url = "MyModule.swf";
this.moduleLoader.loadModule();
this.currentState = "loading";
}
protected function moduleLoader_updateCompleteHandler(event:FlexEvent):void
{
trace("moduleLoader_updateCompleteHandler(event)");
this.moduleLoader.removeEventListener(FlexEvent.UPDATE_COMPLETE, moduleLoader_updateCompleteHandler);
this.currentState = "ready";
}
]]>
</fx:Script>
<s:states>
<s:State name="login" />
<s:State name="loading" />
<s:State name="ready" />
</s:states>
<s:ModuleLoader id="moduleLoader" top="0" left="0" bottom="0" right="0"
updateComplete="moduleLoader_updateCompleteHandler(event)" />
<s:Button label="Login" horizontalCenter="0" verticalCenter="0" includeIn="login" click="login_clickHandler(event)" />
<mx:ProgressBar id="progressBar" source="{this.moduleLoader}" horizontalCenter="0" verticalCenter="0"
includeIn="loading" />
</s:WindowedApplication>
我的模块.mxml
<s:Module xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:s="library://ns.adobe.com/flex/spark" width="100%" height="100%"
creationComplete="module1_creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
/**
* Let's embed a video to simulate load time..
*/
[Embed(source = "VID_20130603_212046.mp4", mimeType = "audio/mpeg")]
private static const VIDEO_SOURCE:Class;
protected function module1_creationCompleteHandler(event:FlexEvent):void
{
trace("MyModule.module1_creationCompleteHandler(event)");
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Panel top="40" left="40" bottom="40" right="40">
<s:Label text="Hello World" horizontalCenter="0" verticalCenter="0" />
</s:Panel>
</s:Module>
这将使主应用程序窗口的启动时间降至最低,并在加载所有繁重资源之前为您提供一个入口点。
更新
查看更新中的示例项目后,您只需在 ViewStack 中设置 creationPolicy="auto",而不是“all”。将其设置为 all 将尝试在单个更新中实例化堆栈中的每个视图,这几乎可以保证锁定线程。
这很可能足以满足您的用例,而不必乱用模块。