我有一个加载 swiz.modules.Module/ 的 swiz 应用程序,该模块也使用 Swiz。当我从 FlashBuilder 运行该应用程序时,它可以正常工作。发布版本在浏览器中无法正常工作。模块的表示模型不会注入视图(模块)。Apache Flex 4.13 Flash player 11.5 任何浏览器
这是我的代码
应用
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:config="swiz.conf.*"
xmlns:swiz="http://swiz.swizframework.org"
width="955"
height="600"
addedToStage="application1_addedToStageHandler(event)">
<fx:Script>
<![CDATA[
// to enable managers inside modules
import mx.managers.CursorManager;
import mx.managers.DragManager;
import mx.managers.PopUpManager;
import mx.managers.ToolTipManager;
import mx.core.EmbeddedFontRegistry;
private var popUpManager:PopUpManager;
private var dragManager:DragManager;
private var tooltipManager:ToolTipManager;
private var _cursorManager:CursorManager;
private var embeddedFontRegistry:EmbeddedFontRegistry;
import swiz.pm.AppPM;
[Inject]
public var appPM:AppPM;
protected function application1_addedToStageHandler(event:Event):void
{
appPM.viewAddedToStage();
}
]]>
</fx:Script>
<fx:Declarations>
<swiz:Swiz id="mySwiz" >
<swiz:beanProviders>
<config:MainApplicationBeans/>
</swiz:beanProviders>
<swiz:config>
<swiz:SwizConfig viewPackages="swiz.views.*"
eventPackages="swiz.events.*"/>
</swiz:config>
</swiz:Swiz>
</fx:Declarations>
<mx:UIComponent id="modulesContainer"/>
应用控制器
package swiz.controllers
{
import mx.events.ModuleEvent;
import spark.modules.ModuleLoader;
import org.swizframework.controller.AbstractController;
import swiz.models.AppModel;
import swiz.pm.AppPM;
public class AppController extends AbstractController
{
[Inject]
public var appPM:AppPM;
[Inject]
public var appModel:AppModel;
protected var modulesLoader:ModuleLoader;
[PostConstruct]
public function initHandler():void
{
modulesLoader = new ModuleLoader();
}
[EventHandler(event="AppPMEvent.VIEW_ADDED")]
public function viewAddedHandler():void
{
appPM.addModuleLoader(modulesLoader);
//load first module
modulesLoader.addEventListener(ModuleEvent.READY,moduleReadyHandler);
modulesLoader.url = appModel.firstModulePath;
}
protected function moduleReadyHandler(event:ModuleEvent):void
{
trace("module loaded but not inited yet");
}
}
}
AppSwizConfig
<?xml version="1.0" encoding="utf-8"?>
<swiz:BeanProvider xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:swiz="http://swiz.swizframework.org"
xmlns:controllers="swiz.controllers.*"
xmlns:pm="swiz.pm.*"
xmlns:models="swiz.models.*" >
<!-- CONTROLLERS -->
<controllers:AppController id="appController"/>
<!-- MODELS -->
<models:AppModel id="aappModel"/>
<!-- PM -->
<pm:AppPM id="appPM"/>
应用程序PM
package swiz.pm
{
import flash.events.IEventDispatcher;
import spark.modules.ModuleLoader;
import swiz.events.AppPMEvent;
// application view presentation module
public class AppPM
{
[Dispatcher]
public var dispatcher:IEventDispatcher;
protected var view:SwizFlexSparkModulesTest;
[ViewAdded]
public function viewAddedHandler(_view:SwizFlexSparkModulesTest):void
{
view = _view;
}
public function viewAddedToStage():void
{
var event:AppPMEvent = new AppPMEvent(AppPMEvent.VIEW_ADDED);
dispatcher.dispatchEvent(event);
}
public function addModuleLoader(value:ModuleLoader):void
{
view.modulesContainer.addChild(value);
}
}
}
模块: FirstModule
<?xml version="1.0" encoding="utf-8"?>
<s:Module xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:ns="http://swiz.swizframework.org"
xmlns:conf="swiz.modules.FirstModule.swiz.conf.*"
width="100%"
height="100%" >
<fx:Declarations>
<ns:Swiz id="mySwiz" >
<ns:beanProviders>
<conf:FirstModuleBeans/>
</ns:beanProviders>
<ns:config>
<ns:SwizConfig viewPackages="swiz.modules.FirstModule.*"
eventPackages="swiz.modules.FirstModule.events.*"/>
</ns:config>
</ns:Swiz>
</fx:Declarations>
<fx:Script>
<![CDATA[
import swiz.modules.FirstModule.swiz.pm.FirstModulePM;
[Inject]
public var pm:FirstModulePM;
protected function btn_clickHandler(event:MouseEvent):void
{
trace("pm = "+pm);
log.appendText("pm = "+pm);
}
]]>
</fx:Script>
<s:VGroup width="100%" height="100%" horizontalAlign="center" verticalAlign="middle">
<s:Label text="first module"/>
<s:Button label="Load second module"
id="btn"
click="btn_clickHandler(event)"/>
<s:TextArea id="log"/>
</s:VGroup>
第一个模块 swiz 配置
<?xml version="1.0" encoding="utf-8"?>
<swiz:BeanProvider xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:swiz="http://swiz.swizframework.org"
xmlns:pm="swiz.modules.FirstModule.swiz.pm.*">
<!-- PM -->
<pm:FirstModulePM id="pm"/>
第一个模块 PM(演示模型)
package swiz.modules.FirstModule.swiz.pm
{
import flash.events.IEventDispatcher;
public class FirstModulePM
{
[Dispatcher]
public var dispatcher:IEventDispatcher;
}
}