您的位置:首页 > 其它

Flex显示图片的几种方式

2016-11-20 16:33 316 查看
<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" 

   creationComplete="init()"  >

 <mx:Script>

  <![CDATA[

   //第一种方式

   [Bindable]

   [Embed(source="image/aa.jpg")]

   private var imgClass:Class;

   

   private var _loader:Loader;

   public function init():void

   {

    //第二种方式

    img4.source="image/aa.jpg";

    //第三种方式

    _loader=new Loader();

    _loader.contentLoaderInfo.addEventListener(Event.COMPLETE,function(e:Event):void

    {

     img5.source=e.currentTarget.content;

    })

    _loader.load(new URLRequest("image/aa.jpg"));

    //这里说一个技巧  当url 中有中文字体的话 使用encodeURI方法 如果没有 则可以不加

    //_loader.load(new URLRequest(encodeURI("中国.jpg")));
   }

  ]]>

 </mx:Script>

 <mx:VBox>

  

  <!-- 第四种方式-->

  <mx:Image source="image/aa.jpg" id="img" width="20%" height="20%"/>

  <!-- 第五种方式-->

  <mx:Image source="@Embed('image/aa.jpg')" id="img2" width="20%" height="20%"/>

  <mx:Image source="{imgClass}" id="img3" width="20%" height="20%"/>

  <mx:Image id="img4" width="20%" height="20%"/>

  <mx:Image id="img5" width="20%" height="20%"/>

 </mx:VBox>

</mx:Application>

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: