2014-09-21 49 views
0

我有一個加載swiz.modules.Module的Swiz應用程序/該模塊也使用Swiz。 當我從FlashBuilder運行它時,該應用程序正常工作。 發佈頁面在瀏覽器內部工作不正常。模塊的演示模型不會注入視圖(模塊)。 阿帕奇的Flex 4.13 Flash播放器11.5 任何瀏覽器SWIZ框架在flex中缺少PresentationModel spark.modules.Module

這裏是我的代碼

應用

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

AppController的

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

appPM

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(prezentation模型)

package swiz.modules.FirstModule.swiz.pm 
{ 
import flash.events.IEventDispatcher; 

public class FirstModulePM 
{ 
    [Dispatcher] 
    public var dispatcher:IEventDispatcher; 
} 

}

回答

0

錯誤你的發行版得到什麼? 如果它找不到某些類,那麼在構建發佈時可能會忽略它們,因爲它們沒有鏈接。 嘗試添加compile flag「鏈接報告文件名」以查看是否有所有必需的類都可以使您的應用程序正常工作。更多信息Examining linker dependencies

要強制鏈接它們,只需將主應用程序中的導入添加到缺失的類。組織進口時要小心。

+0

**要強制鏈接它們,只需將主應用程序中的導入添加到缺失的類。**是。有用。謝謝。 – 2014-10-22 13:11:43