代码之家  ›  专栏  ›  技术社区  ›  Anshuman Jaiswal

在运行时更改图像源

  •  2
  • Anshuman Jaiswal  · 技术社区  · 16 年前

    3 回复  |  直到 16 年前
        1
  •  1
  •   Amarghosh    16 年前

    呼叫 image.validateNow() 在设置 source 立即强制改变。

        2
  •  2
  •   Lance Pollard    16 年前

    如果要将源设置为url(例如 image.source = "/assets/myimage.jpg" ),则可能需要1+帧才能加载映像,因为它正在发出异步URL请求,因此不会立即注册更改。使命感 validateNow() 在那种情况下没用。

    如果需要立即加载,可以嵌入图像(如果图像足够小),或者一次加载几个图像并将其存储在某个位置,然后将图像源设置为位图(类似于 image.source = myImageCache.getBitmap(0); ).

    希望有帮助, 用刀切开

        3
  •  1
  •   Anuj Sharma    12 年前

    尝试一个简单的技巧。只需添加两个图像组件,一个为真,另一个为假。单击事件后,只需更改图像组件的可见性。你会得到想要的结果。

    <fx:Script>
            <![CDATA[
    
    private var isPause:Boolean=false;
    
    protected function music_control1(event:MouseEvent):void
                {
                    if(!isPause)
                    {
                        pos =_channel.position;
                        isPause=true;
                        SoundMixer.stopAll();
                        music2.visible=true;
                        music.visible=false;
                    }
                    else
                    {
                        music.enabled=true;
                        _channel=_sound.play();
                        isPause=false;
                        music2.visible=false;
                        music.visible=true;
                    }
    
                }
    ]]>
        </fx:Script>
    
    
        <s:Image id="music" x="200" y="245" click="music_control1(event)"
                         source="@Embed('assets/pause.png')"/>      
                <s:Image id="music2" x="200" y="245" click="music_control1(event)" visible="false"
                         source="@Embed('assets/play.png')"/>
    
    推荐文章