Flex中的嵌入资源(Embedding Assets)——Swingguy摘译自Flex 3 Developer's Guide
来源:互联网 发布:日语打字练习软件 编辑:程序博客网 时间:2024/06/09 15:40
Flex软件中经常需要使用一些外部的资源,如图片、声音、SWF或字体,虽然你也可以在软件运行的时候引入和载入,但是也可能经常需要直接将这些资源编译(Compile)到软件中,也就是直接嵌入资源(EmbeddingAssets)。Flex中可以直接嵌入图片image,影片movie,MP3,和TrueType文字。
嵌入资源的利处:
1、比起在运行时访问资源,对嵌入资源的访问速度更加快速;
2、可以用简单的变量访问方式,在多个地方引用所嵌入的资源。这是变量就代表资源,提高写代码的效率;
嵌入资源的弊处:
1、增大了SWF文件的大小,因为是将资源直接包含;
2、由于SWF文件增大,将使得初始化的速度变慢;
3、当资源改变后,需要重新编译SWF文件;
例子1:一个简单的嵌入资源的例子:
<?xml version=”1.0”?>
<!-- embed/ButtonIcon.mxml -->
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml”>
<mx:Button label=”Icon Button” icon=”@Embed(source=’logo.gif’)"/>
</mx:Application>
以上粗体部分,使用了@Embed()指令,将logo.gif这个图片直接嵌入到程序中,作为Button按钮的Icon图标。
例子2:用变量引用嵌入的资源
<?xml version="1.0"?>
<!-- embed/ButtonIconClass.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
[Embed(source="logo.gif")]
[Bindable]
public var imgCls:Class;
]]>
</mx:Script> ADOBE FLEX 3 BETA 2
<mx:Button label="Icon Button 1" icon="{imgCls}"/>
<mx:Button label="Icon Button 2" icon="{imgCls}"/>
以上粗体部分,表示将logo.gif图片嵌入,并让变量imgCls可以引用该资源。[Bindable]表示该变量imgCls是可以被数据绑定的。之后,就可以在多个地方引用该嵌入资源的变量(见红色粗体)。
另外也可以通过Embed()指令,在样式表中嵌入资源,这通常是在设置UI组件的皮肤时候使用。如下代码:
<?xml version="1.0"?>
<!-- embed/ButtonIconCSS.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Style>
.myCustomButton {
overSkin:Embed(source="overIconImage.gif");
upSkin:Embed(source="upIconImage.gif");
downSkin:Embed(source="downIconImage.gif");
}
</mx:Style>
<mx:Button label="Icon Button Style Def" styleName="myCustomButton"/>
</mx:Application>
以上代码表示在按钮的常态(up)、鼠标悬停(over)、鼠标按下(down)的状态,使用不同的皮肤。overSkin、 upSkin、downSkin是Button的对应状态下的皮肤属性。
可嵌入的资源文件格式:
<!-- embed/Embed9slice.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
width="1200" height="600">
<mx:Script>
<![CDATA[
[Embed(source="slice_9_grid.gif",
scaleGridTop="25", scaleGridBottom="125",
scaleGridLeft="25", scaleGridRight="125")]
public var imgCls:Class;
]]>
</mx:Script>
<mx:HBox>
<mx:Image source="{imgCls}"/>
<mx:Image source="{imgCls}" width="300" height="300"/>
<mx:Image source="{imgCls}" width="450" height="450"/>
</mx:HBox>
</mx:Application>
- Flex中的嵌入资源(Embedding Assets)——Swingguy摘译自Flex 3 Developer's Guide,转载请注明
- Flex中的嵌入资源(Embedding Assets)——Swingguy摘译自Flex 3 Developer's Guide
- Flex中的嵌入资源(Embedding Assets)
- Flex中的嵌入资源
- flex:嵌入应用程序资源
- Flex嵌入应用程序资源
- flex 嵌入其他资源
- flex:嵌入应用程序资源
- Flex 3: A Beginner's Guide
- Flex中的嵌入图片
- flex 图片资源嵌入用法
- 在Flex (Flash)中嵌入HTML 代码或页面—Flex IFrame
- 使用FLEX 和 Actionscript开发FLASH 游戏—嵌入资源和增加游戏元素
- flex中使用Embed方式嵌入资源
- flex中使用Embed方式嵌入资源
- Getting Started with Flex 3: An Adobe Developer Library Pocket Guide for Developers
- The X New Developer’s Guide——前言
- The X New Developer’s Guide——第一章 基本概念
- Domino之地址本
- Ext 3探胜
- 利用java操作Excel文件
- Get reusable DB connection
- 分享IKAnalyzer 3.0 中文分词器
- Flex中的嵌入资源(Embedding Assets)——Swingguy摘译自Flex 3 Developer's Guide
- Linux下semop等待信号时出现Interrupted System Call错误(EINTR)
- 在asp.net webservice中如何使用session
- 博客的力量
- 再次碰到:a different object with the same identifier value was already associated with the session
- Visual Source Safe简介
- 使用SDO_FILTER
- 数据库到底用不用外键、触发器、索引、视图、存储过程
- GifOleControl 1.0.2 功能说明