2011-05-17 51 views
1

我在製作我的第一個Flex移動應用程序(雖然我不是新來的Flex)方面有一個破解,並且我在第一個障礙時跳閘。flex 4 ViewNavigator的移動問題應用狀態和firstView

我無法獲得ViewNavigatorApplication在嘗試使用firstView時顯示視圖,並顯示狀態。 firstView.phonefirstView.tablet

我只剩下一個空白的操作欄和內容區域。

如果我嘗試設置設定的firstView無狀態(例如的firstView = 「view.HomeView」)視圖加載罰款。

下面的代碼:

<s:ViewNavigatorApplication 
    xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    firstView.phone="views.HomeView" 
    firstView.tablet="views.TabletHomeView" 
    applicationDPI="160" 
    creationComplete="initApplication()"> 
    <s:states> 
     <s:State name="portraitPhone" stateGroups="portrait, phone"/> 
     <s:State name="landscapePhone" stateGroups="landscape, phone"/> 
     <s:State name="portraitTablet" stateGroups="portrait, tablet"/> 
     <s:State name="landscapeTablet" stateGroups="landscape, tablet"/> 
    </s:states> 
    <fx:Style source="assets/css/application.css"/> 
    <fx:Script> 
     <![CDATA[ 
      import mx.events.ResizeEvent; 

      private var isPortrait:Boolean; 
      private var isTablet:Boolean; 

      private function initApplication():void 
      {    
       addEventListener(ResizeEvent.RESIZE, resizeHandler); 
       addEventListener(Event.ADDED_TO_STAGE, resizeHandler); 
      } 

      private function resizeHandler(event:*):void 
      { 
       isPortrait = (stage.height > stage.width); 
       isTablet = (stage.height > 950 || stage.width > 950); 

       currentState = (isPortrait ? "portrait" : "landscape") + (isTablet ? "Tablet" : "Phone"); 
      } 
     ]]> 
    </fx:Script> 
</s:ViewNavigatorApplication> 

我GOOGLE了這個死亡,閱讀雖然ViewNavigatorApplication specification並沒有發現任何人有這個問題,或者我只是做錯任何證據(雖然我仍然懷疑是這樣)。

在此先感謝!

+0

我還在學習自己,但如果我理解過程rstand,你不想在ViewNavigatorApplication中創建像這樣的狀態。本質上它只是一個虛擬的容器。在View中創建這樣的狀態。 – JeffryHouser 2011-05-17 12:10:51

回答

2

在我和@ www.Flextras.com評論去年底[不把儘可能一個答案]:

我仍然在學習自己,但如果我明白,你不想 在ViewNavigatorApplication創建像這樣的狀態。本質上,它只是一個虛擬容器 。在View中創建這樣的狀態。

我清空了ViewNavigatorApplication的所有國家&代碼如下所示:

<?xml version="1.0" encoding="utf-8"?> 
<s:ViewNavigatorApplication 
    xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    applicationDPI="160" 
    splashScreenImage="com.mis.editor.mobile.sire.components.DynamicSplash" 
    runtimeDPIProvider="com.mis.editor.mobile.helpers.RuntimeDPIHelper" 
    firstView="SplashView"> 
    <fx:Style source="com/mis/editor/mobile/sire/assets/css/application.css"/> 
</s:ViewNavigatorApplication> 

我把代碼中的第一個視圖來檢測,如果該設備是手機/平板電腦和重定向到相應的View:

protected function push_login():void 
{   
    var fadeTrans:CrossFadeViewTransition = new CrossFadeViewTransition(); 

    if(ScreenDetails.Format == 'phone') 
    { 
     navigator.pushView(PhoneLoginView, appDataMediator, null, fadeTrans); 
    } 
    else 
    { 
     navigator.pushView(LoginView, appDataMediator, null, fadeTrans); 
    }   
} 

感謝您的建議傢伙:-)

0

如果視圖本身是狀態,爲什麼要在視圖導航器中擁有狀態?我相當肯定它並不意味着被這樣使用,並且不可能通過第一視圖「加載」一個新視圖。只需設置第一個視圖並在加載後切換視圖。

如果你想要做的東西,「調整大小」,我會調整大小的代碼添加到每個視圖對每個外形單獨的應用程序,以提供更好的體驗,同時重用你的代碼(這是我的首選方法)。

0

也許你可以嘗試在計算屏幕大小後從actionscrtip中設置firstView屬性。只要確保你在預初始化事件中這樣做。否則它將無法工作。內部意見不viewNavigatorApplication(定義主應用程序文件。ViewNavigatorApplication容器不採取任何子女。)

+0

如果您不確定答案的正確性,請將其作爲評論發佈,而不是回答。 – durron597 2012-11-16 20:56:24