2012-02-26 9 views
1

Flex Mobile Appでは、アプリケーションコンポーネントは、ポートレート/ランドスケープのios/Android、グループの電話機/タブレットなどの状態を処理します。私のビューでは、メインアプリケーションにこれらの特定の状態が1つある場合、ボタンを含めることにしました。私はポートロイト/ランドスケープを確認し、再び自分の状態として設定するようなビューを必要としません。一方、ビューステートは他のものに必要です。では、トップレベルアプリケーションの状態がランドスケープなどの場合にのみ、ビューにボタンを含めるにはどうすればいいですか?Flex includeIn(topLevelApplicationの状態)

答えて

2

それは、複数の状態で存在している場合は、カンマで区切られたリストのすべての

+0

私のアプリケーション状態であればビューでは動作しません。 – MorbZ

+0

FlexGlobals.topLevelApplication.state属性はどうですか? – Mansuro

+0

それは私にエラーを与える。それがうまくいくとは想像できませんでした – MorbZ

1

ファーストを置くことができる属性includein =「風景」を使用してアプリケーションに2つの状態を追加するに:

<s:states> 
    <s:State name="portrait"/> 
    <s:State name="landscape"/> 
</s:states> 

次、あなたの<fx:Script>セクションに次の関数を追加します。

<fx:Script> 
    <![CDATA[ 
     import mx.events.ResizeEvent; 

     protected function application1_resizeHandler(event:ResizeEvent):void 
     { 
      if (width>height) 
       this.currentState="landscape"; 
      else this.currentState="portrait"; 
     } 
    ]]> 
</fx:Script> 

またAPPLに上記のメソッドを呼び出しますication のサイズを変更:

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
      xmlns:s="library://ns.adobe.com/flex/spark" applicationDPI="160" resize="application1_resizeHandler(event)"> 

コンポーネントを含めたり除外したい場合は、単に目的のコンポーネントに見えまたはincludeInを追加します。

visible.landscape="false" 

または

includeIn="landscape" 

フルコードサンプル:

<?xml version="1.0" encoding="utf-8"?> 
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
         xmlns:s="library://ns.adobe.com/flex/spark" 
         xmlns:mx="library://ns.adobe.com/flex/mx" 
         resize="application1_resizeHandler(event)"> 
    <fx:Declarations> 
     <!-- Place non-visual elements (e.g., services, value objects) here --> 
    </fx:Declarations> 

    <s:states> 
     <s:State name="portrait"/> 
     <s:State name="landscape"/> 
    </s:states> 

    <fx:Script> 
     <![CDATA[ 
      import mx.events.ResizeEvent; 

      protected function application1_resizeHandler(event:ResizeEvent):void 
      { 
       if (width>height) 
        this.currentState="landscape"; 
       else this.currentState="portrait"; 
      } 
     ]]> 
    </fx:Script> 
    <s:Button includeIn="landscape" x="58" y="52" label="Landscape"/> 
    <s:Button includeIn="portrait" x="58" y="90" label="Portrait"/> 

</s:WindowedApplication> 
+0

これを行うには最適な方法かもしれません。しかし、パフォーマンス上の理由から、オブジェクトを作成する必要がないため、includeIn/excludeInはvisible = falseおよびincludeInLayout = falseを設定するよりも優れていることを誰もが告げるので、より良い解決策があると思っていました。そしてincludeIn/excludeInはafaikだけ州で利用可能です.. – MorbZ

+0

あなたは正しいですが、上記のコードであなたは状態を持っていて、あなたは 'includeIn/excludeIn'を使うことができます。上記の完全なコードサンプルをご覧ください。 –

+0

ええ、私のアプリケーションコンポーネントにないビューコンポーネントのアプリケーション状態にアクセスしたいです。私の質問を見てください。 – MorbZ

関連する問題