2011-11-15 7 views
0

persistNavigatorState = "true"stage.setAspectRatio(StageAspectRatio.PORTRIT)を一緒に使用してプログラムを初期化できないのはなぜですか?Flex MobileなぜpersistNavigatorState = "true"で、stage.setAspectRatio(StageAspectRatio.PORTRAIT)は混在しませんか?

<s:View ...creationComplete="init()"> 

保護された関数init():ボイド{

stage.setAspectRatio(StageAspectRatio.PORTRAIT)。
}

[SWF] Main.swf - 3,394,828 bytes after decompression 
    TypeError: Error #1009: Cannot access a property or method of a null object reference. 
    at views::Try01/init()[C:\Users\James\Adobe Flash Builder 4.5\myProgram\src\views\Try01.mxml:19] 
    at views::Try01/___Try01_View1_creationComplete()[C:\Users\James\Adobe Flash Builder 4.5\myProgram\src\views\Try01.mxml:4] 
    at flash.events::EventDispatcher/dispatchEventFunction() 
    at flash.events::EventDispatcher/dispatchEvent() 
    at mx.core::UIComponent/dispatchEvent()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\core\UIComponent.as:13128] 
    at mx.core::UIComponent/set initialized()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\core\UIComponent.as:1818] 
    at mx.managers::LayoutManager/validateClient()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\managers\LayoutManager.as:1090] 
    at mx.core::UIComponent/validateNow()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\core\UIComponent.as:8067] 
    at spark.components::ViewNavigator/commitNavigatorAction()[E:\dev\4.5.1\frameworks\projects\mobilecomponents\src\spark\components\ViewNavigator.as:1878] 
    at spark.components::ViewNavigator/commitProperties()[E:\dev\4.5.1\frameworks\projects\mobilecomponents\src\spark\components\ViewNavigator.as:1236] 
    at mx.core::UIComponent/validateProperties()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\core\UIComponent.as:8209] 
    at mx.managers::LayoutManager/validateProperties()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\managers\LayoutManager.as:597] 
    at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\managers\LayoutManager.as:783] 
    at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\managers\LayoutManager.as:1180] 

私はpersistNavigatorStateを有効にするたびに、私のプログラムは実行されません。両方を一緒に使用する方法はありますか?おかげ

[ライン4] creationComplete="init()"

protected function init():void { 


[Line 19] stage.setAspectRatio(StageAspectRatio.PORTRAIT); 

    } 
+0

あなたが "逃げない" とはどういう意味ですか?間違いはありますか?または、アプリケーションが読み込まれませんか?それとも、ロードしてすぐにクラッシュするのですか?どのプラットフォームをターゲットにしていますか?ビヘイビアはエミュレータまたはデバイスに存在しますか? – JeffryHouser

+0

モバイルエミュレータで動作していますが、エラーが多く、エミュレータがハングアップしても、デバイスを試すためのイベントを構築できません。あなたがエラーを知りたければ、私に知らせて、私はそれを投稿します。 (FB 4.5.1を使用) – jameslcs

+0

エミュレータとの問題がたくさんあります。しかし、あなたが漠然とした方向性を求めているなら、エラーを投稿する必要があります。 – JeffryHouser

答えて

2

はおそらく、ステージの前にcreationCompleteイベント火災はアクセス可能です。 persistNavigatorStateを使用すると、永続性キャッシュからナビゲータの状態情報を最初に取得することによって、アプリケーションの起動動作が少し変更されます。 Flexドキュメントのこの行は、アプリケーションが再起動するときにと表示されます。現在のViewNavigatorの状態のみが復元されます。また、オブジェクトがdisplayListに追加されるまで、flexのステージにはアクセスできません。したがって、ステージが空のときにsetAspectRatioを呼び出すと、null obj参照が取得されます。

creationCompleteでstage.setAspectRatio(StageAspectRatio.PORTRAIT)を使用する代わりに、<aspectRatio>portrait</aspectRatio>などをapp.xmlに設定してみることができます。

または、あなたのビューでaddedToStageイベントをリッスンし、イベントハンドラでstage.setAspectRatio(StageAspectRatio.PORTRAIT)を呼び出すことができます。そうすれば、ステージが利用可能であることを確実に知ることができます。

参考文献:

+0

私は多くの種類のイベントリスナーを使用しようとしていますが、addedToStageは試していません。素晴らしい提案をありがとう、それは動作します! – jameslcs

+0

addedToStageイベントの記述に+1します。私は前に私の心に浮かぶことはないと信じられない。 – JeffryHouser

関連する問題