Flex Image 加载的几种方式

Flex 加载图片的几种方式:

1.直接标签加入,嵌入swf中

<mx:Image source="@Embed(source='view/test1.png')"/>

2.直接标签加入,动态加入swf中

<mx:Image source="view/test1.png"/>

3.定义变量绑定

[Embed(source='view/test.png')]
[Bindable]private var imageSource:Class; 
<mx:Image source="{imageSource}"/>

 4.As代码加入

var img:Image = new Image();
img.source = imageSource;
this.addElement(img);

或者

var img:Image = new Image();
img.source = "view/test.png";
this.addElement(img);

5.嵌入外部swf中的图片

 

 1.在fla的库中添加一张图片,选中图片右键-属性-定义它的导出类.例如:imgpng。fla会自动的赋值它的基类为:flash.display.BitmapData。

  2.导出为swf,放到flexbulider中。我放到了view文件夹下面。

 

[Embed(source='view/test.swf',symbol=='imgpng')]
[Bindable]private var imageSource:Class; 
<mx:Image source="{imageSource}"/>

 

 

6.从外部swf中动态加载

  1.在fla的库中添加一张图片,选中图片右键-属性-定义它的导出类.例如:imgpng。fla会自动的赋值它的基类为:flash.display.BitmapData。

  2.导出为swf,放到flexbulider中。我放到了view文件夹下面。

  3.加载此swf

 

  var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoadComplete);
var request:URLRequest = new URLRequest("view/test.swf");
loader.load(request);

private function onLoadComplete(event:Event):void
{
	var imgpng:Class = (event.target as LoaderInfo).applicationDomain.getDefinition("imgpng") as Class;
	var dataBitmpa:Bitmap = new Bitmap(new imgpng(1000,1000));
	image.source = dataBitmpa;
				
	var dataBitmapAsset:Class = sourceLoadUtility.getClass(new imgpng(1000,1000));
	button.setStyle("icon",dataBitmapAsset); 
}

 package com.benstucki.utilities

 

{
	import flash.display.BitmapData;
	import flash.events.Event;
	
	import mx.core.BitmapAsset;
	import mx.core.UIComponent;

	public class sourceLoadUtility extends BitmapAsset
	{
		private static var sourceBitMapData:BitmapData;
		public static function getClass(sourceBitMapData1:BitmapData):Class {
			sourceBitMapData = sourceBitMapData1;
			return sourceLoadUtility;
		}
		public function sourceLoadUtility():void {
			addEventListener(Event.ADDED, addedHandler, false, 0, true)
		}
		private function addedHandler(event:Event):void {
			if(!bitmapData) {
				bitmapData = new BitmapData(100, 100, true, 0x00FFFFFF);
			}
			bitmapData.draw(sourceBitMapData);
			if(parent is UIComponent) {
				var component:UIComponent = parent as UIComponent;
				component.invalidateSize();
			}
		}
	}
}

   (image是图片,button是按钮)

 

 

PS:BitmapAsset 是 flash.display.Bitmap 类的子类,表示您在 Flex 应用程序中嵌入的位图图像。它用于实现 IFlexDisplayObject 接口,此接口允许在 Image 控件中显示嵌入的位图图像,或将位图图像用作容器背景或组件外观。

 你也可以参考IconUtility.as类来用。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值