Flex之Embed应用

转自:http://wwm86.blog.51cto.com/1249181/394644

使用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> 

上例中表示将btnIcon.png图片嵌入,同时用变量imgClass可以引用嵌入的资源,[Bindable]  表示数据绑定,在按钮<mx:Button />中可以引用此资源。overIcon按钮显示的图片,downIcon表示按钮按下时的图片样式。

  在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>

上例使用了@Embed()指令将图片嵌入,作为按钮的Icon图标。

在<mx:style></mx:Style>样式中定义。

Embed(parameter1,parameter2,... ) 指令

       例如:

<mx:Style>
.myIcon 
{ 
downIcon : Embed(source = "image/btnIcon3.png" ); 
} 
</mx:Style>
<mx:Panelwidth="690"height="328"id="panel">
<!--使用样式定义按钮图片 -->
<mx:Buttonlabel="Style"styleName="myIcon"/>
</mx:Panel>

上例中使用了Embed指令在样式表定义了嵌入资源,可以设置UI组件的皮肤。

转载于:https://www.cnblogs.com/mikevictor07/archive/2012/09/09/2677870.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值