Flex之Embed应用
时间:2010-09-20 来源:wwmlx86
使用Flex开发时,经常会引用外部的资源,如图片、MP3、视频等资源。虽然我们可以在运行时载入,但运行时载入可能会影响访问的时间,通常我们需要在直接将这些资源编译到程序中,也就是Embedding assets(嵌入资源)。
Flex可以使用Embed嵌入图片(image)、影片(movice)、Mp3等,有三种嵌入资源的方式可供选择,语法如下:
- 在ActionScript文件中定义,或者在<mx:Script></mx:Script>标签中定义。
- [Embed(parameter1,parameter2,...)] 元数据
- <mx:Script>
- <![CDATA[
- [Embed(source = "image/btnIcon.png" )]
- [Bindable]
- private var imgClass:Class;
- ]]>
- </mx:Script>
- <mx:Panel width="690" height="328" id="panel">
- <!--使用变量嵌入 -->
- <mx:Button label="Embedding assets1" overIcon="{imgClass}" />
- <mx:Button label="Embedding assets2" downIcon="{imgClass}" />
- </mx:Panel>
- 在MXML中需要使用的标签内直接嵌入。
- @Embed(parameter1,parameter2,...) 指令
- <mx:Panel width="690" height="328" id="panel">
- <!--直接嵌入图片 -->
- <mx:Button label="Test Icon" icon="@Embed(source='image/btnIcon2.png')" width="136"/> </mx:Panel>
- 在<mx:style></mx:Style>样式中定义。
- Embed(parameter1,parameter2,... ) 指令
- <mx:Style>
- .myIcon
- {
- downIcon : Embed(source = "image/btnIcon3.png" );
- }
- </mx:Style>
- <mx:Panel width="690" height="328" id="panel">
- <!--使用样式定义按钮图片 -->
- <mx:Button label="Style" styleName="myIcon" />
- </mx:Panel>
例如:
上例中表示将btnIcon.png图片嵌入,同时用变量imgClass可以引用嵌入的资源,[Bindable] 表示数据绑定,在按钮<mx:Button />中可以引用此资源。overIcon按钮显示的图片,downIcon表示按钮按下时的图片样式。
例如:
上例使用了@Embed()指令将图片嵌入,作为按钮的Icon图标。
例如:
上例中使用了Embed指令在样式表定义了嵌入资源,可以设置UI组件的皮肤。
相关阅读 更多 +