使用Loader,运行时加载图片

BitmapImage只能在使用@Embed位图,要想在运行时加载,可以参考下面的代码

 

 1  <? xml version="1.0" encoding="utf-8" ?>
 2  < s:Application  xmlns:fx ="http://ns.adobe.com/mxml/2009"  
 3                 xmlns:s ="library://ns.adobe.com/flex/spark"  
 4                 xmlns:mx ="library://ns.adobe.com/flex/mx"  minWidth ="955"  minHeight ="600"
 5                 creationComplete ="application1_creationCompleteHandler(event)" >
 6     
 7      < fx:Script >
 8          <![CDATA[
 9              import mx.controls.Alert;
10              import mx.events.FlexEvent;
11 
12              protected function application1_creationCompleteHandler(event:FlexEvent):void
13              {
14                  var loader:Loader = new Loader();
15                  loader.contentLoaderInfo.addEventListener(Event.COMPLETE, handleLoaderComplete);
16                  loader.load(new URLRequest("assets/google.png"));
17              }
18              
19              private function handleLoaderComplete(event:Event):void
20              {
21                   var bmp:Bitmap = LoaderInfo(event.target).content as Bitmap;
22                  bf.source = bmp; 
23              }
24              
25           ]]>
26      </ fx:Script >
27     
28      < fx:Declarations >
29          <!--  将非可视元素(例如服务、值对象)放在此处  -->
30      </ fx:Declarations >
31     
32      < s:layout >
33          < s:VerticalLayout  />
34      </ s:layout
35      
36      <s:Graphic >
37          < s:Group >
38              < s:Ellipse  width ="300"  height ="300" >
39                  < s:fill >
40                      < s:BitmapFill  id ="bf"  fillMode ="repeat" />
41                  </ s:fill >
42                 
43              </ s:Ellipse >
44          </ s:Group >
45      </ s:Graphic >
46     
47     
48  </ s:Application >

 

转载于:https://www.cnblogs.com/iihe602/archive/2012/04/10/2440631.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值