加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Flex Image 加载的几种方式

发布时间:2020-12-15 04:45:00 所属栏目:百科 来源:网络整理
导读: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 imag

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,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类来用。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读