flex中image控件source属性改变的例子

时间:2023-03-08 17:22:41
Download: main.mxml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
  3. layout="vertical"
  4. verticalAlign="middle"
  5. backgroundColor="white">
  6. <mx:Script>
  7. <![CDATA[
  8. import mx.controls.Alert;
  9. private function init():void {
  10. img.addEventListener("sourceChanged", image_sourceChanged);
  11. }
  12. private function image_sourceChanged(evt:Event):void {
  13. Alert.show(evt.toString(), evt.type);
  14. }
  15. ]]>
  16. </mx:Script>
  17. <mx:ApplicationControlBar dock="true">
  18. <mx:Button label="Flash"
  19. click="img.source = 'assets/fl_appicon.jpg';" />
  20. <mx:Button label="Flash Player"
  21. click="img.source = 'assets/fl_player_appicon.jpg';" />
  22. <mx:Button label="Flex"
  23. click="img.source = 'assets/fx_appicon.jpg';" />
  24. </mx:ApplicationControlBar>
  25. <mx:Image id="img"
  26. source="assets/fx_appicon.jpg"
  27. initialize="init();"
  28. width="100"
  29. height="100" />
  30. </mx:Application>