0

特定の背景画像を持つコンポーネントがあります。コードは次のようになります。

<mx:backgroundImage>@Embed(source='img1.png')</mx:backgroundImage>

<mx:states>
  <mx:State name='state2'>
    <mx:SetStyle name="backgroundImage">
      <mx:value>@Embed(source='img2.png')</mx:value>
    </mx:SetStyle>
  </mx:State>
</mx:states>

しかし、状態をに変更して'state2'も、実際には何も変更されません。

ここで何か具体的なことが欠けていますか?

4

3 に答える 3

1

デフォルトのターゲットはメインアプリです。したがって、実際には、コンポーネントではなく、state2で​​アプリ全体の背景を設定しています。これがVBoxの例です

<?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:states>
    <mx:State name="state2">
        <mx:SetStyle name="backgroundImage" target="{VBox1}">
            <mx:value>
                @Embed(source='img2.jpg')
            </mx:value>
        </mx:SetStyle>
    </mx:State>
</mx:states>
<mx:VBox id="VBox1" x="0" y="0" width="50%" height="50%">
    <mx:backgroundImage>
        @Embed(source='img1.jpg')
    </mx:backgroundImage>
</mx:VBox>

</mx:Application>

また、Flex 3 Builderを使用している場合は、いつでもデザインモードに切り替えて、基本状態から新しい状態への変更を確認できます。右上隅にあるはずです。

コンポーネントの編集

メインファイル

<cbsh:BackSwitch>

</cbsh:BackSwitch>

</mx:Application>

成分

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300">
<mx:states>
    <mx:State name="state2">
        <mx:SetStyle name="backgroundImage" target="{this}">
            <mx:value>
                @Embed(source='img2.jpg')
            </mx:value>
        </mx:SetStyle>
    </mx:State>
</mx:states>
<mx:backgroundImage>
        @Embed(source='img1.jpg')
    </mx:backgroundImage>
<mx:Button x="437" y="269" label="Switch!" click="currentState='state2';"/>
</mx:VBox>
于 2010-06-04T02:55:17.127 に答える
0

私はこれを具体的に扱っていませんが、私の直感では、値の設定方法に問題があります。これを試しましたか:

mx:setStyle setStyle name = "backgroundImage value =" @ Embed(source ='img2.png') "/>

于 2010-06-04T02:39:53.727 に答える
0

これは一種の奇妙なエラーのように思われるので、私の一時的な解決策は、状態に応じて可視性を反転させる異なる背景を持つ2つのキャンバスを用意することです

于 2010-06-04T03:21:33.037 に答える