Flex Image 加载的几种模式
1个回答
展开全部
Flex 加载图片的几种方式:1.直接标签加入,嵌入swf中2.直接标签加入,动态加入swf中3.定义变量绑定�0�2�0�2[Embed(source='view/test.png')][Bindable]private var imageSource:Class; �0�24.As代码加入�0�2�0�2var img:Image = new Image();img.source = imageSource; this.addElement(img);或者�0�2�0�2var img:Image = new Image(); img.source = "view/test.png"; this.addElement(img);�0�25.从外部swf中动态加载�0�21.在fla的库中添加一张图片,选中图片右键-属性-定义它的导出类.例如:imgpng。fla会自动的赋值它的基类为:flash.display.BitmapData。�0�22.导出为swf,放到flexbulider中。我放到了view文件夹下面。�0�23.加载此swf�0�2 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); }�0�2package com.benstucki.utilities�0�2{ 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(); } } } }�0�2�0�2(image是图片,button是按钮)�0�2�0�2PS:BitmapAsset 是 flash.display.Bitmap 类的子类,表示您在 Flex 应用程序中嵌入的位图图像。它用于实现 IFlexDisplayObject 接口,此接口允许在 Image 控件中显示嵌入的位图图像,或将位图图像用作容器背景或组件外观。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询