0

Flexアプリケーションで作業していて、ボタンアイコンソースを動的に更新する必要がありますが、実行時にアイコン属性を別のクラス変数に変更するだけでは不十分で、クラスソースを別のものに明示的に変更する必要があります。私は疑問をグーグルで検索しましたが、まだ答えがありません。

次のようなものが欲しい: http://www.java2s.com/Code/Flex/Graphics/ChangeImagesourceinbuttonaction.htm

しかし、代わりにこのようなことをする必要があります:

[Embed(source="sun.jpg")]
[Bindable]
private var dayAsset:Class;

private function init(  ):void {
    dayImage.source = dayAsset;
}

private function showMoon(  ):void {
    dayAsset.source = "moon.jpg";
}

private function showSun(  ):void {
    dayAsset.source = "sun.jpg";
}

以前のコードを試しましたが成功しませんでした。

「dayImage」画像ソースをこのように更新する必要があるのはなぜですか?? 複数の場所で参照されている画像があり、トリガーされたイベントですべてを更新する必要があるため

解決策:Pまたはコメントは大歓迎です。

ありがとう。素敵な夜を過ごす。

4

1 に答える 1

0

質問を理解した場合; 答えは、実行時に埋め込みを変更できないということです。それらはコンパイル時に実行されます。コンパイルした SWF の一部にします。

ほとんどの場合、次のようなアプローチを実行する必要があります。

// embed both images
[Embed(source="sun.jpg")]
[Bindable]
private var dayAssetSun:Class;

[Embed(source="moon.jpg")]
[Bindable]
private var dayAssetMoon:Class;

// us a variable to store the reference to the image you want to see
private var currentDayAsset :Class;

// set the current asset
private function init(  ):void {
    dayImage.source = currentDayAsset;
}

// these methods change the currentDayAsset variable; but do not affect the embeds
private function showMoon(  ):void {
    currentDayAsset =  dayAssetMoon;
}

private function showSun(  ):void {
    currentDayAsset =  dayAssetSun;
}
于 2012-12-02T13:30:15.997 に答える