移动设备:嵌入图像以提高速度
在移动 Air 应用程序中嵌入图像会加快绘制使用图像的 UI 的过程吗?
如何正确嵌入图像?
谢谢!
Would embedding images in mobile Air applications speed up the process of drawing the UI that uses images?
How does one properly embed the images?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嵌入图像的优点是它包含在 SWF 文件中,并且比应用程序必须在运行时从远程位置加载图像时访问速度更快。但它也有一个缺点,即您的 SWF 文件比在运行时加载资源时要大。
嵌入过程非常简单,只需按照以下步骤操作即可:
将图像文件复制到应用程序的“src”文件夹中。 Flex 4将从那里获取这些文件。当然,您可以定义子文件夹以免混乱。
在你的类中定义如下例所示
[嵌入(源=“728x90a.jpg”)]
公共静态常量 imgData1:Class;
在代码中的某个位置,将数据加载到可视组件中,如下例所示
img1.source=imgData1;
img1 是一个图像组件。
<前><代码>包
{
公共类 TestProjectAssets
{
[嵌入(来源=“字体/MySuperDuperFont.otf”,
fontFamily="SuperDuperFont",
mimeType="应用程序/x-font",
embedAsCFF="true")]
私有 const SuperDuperFont:Class;
[嵌入(源=“资产/mainMenu.png”)]
公共静态常量mainMenuImg:类;
}
}
如果您需要处理大量资源,可以按照以下 3 个步骤进行操作:
如果您选择涉及加载外部文件的不同方法,请注意某些 Flash 游戏网站要求其托管的游戏包含在单个 swf 文件中。
The advantage of embedding an images is that it is included in the SWF file, and can be accessed faster than it can if the application has to load it from a remote location at run time. but it also have disadvantage that is your SWF file is larger than if you load the asset at run time.
The embed process is very simple, just follow to follow steps:
copy your image files where the "src" folder is of your application. the Flex 4 will get these files from there. Of course you may define sub folders to do not mess up.
In your class define like the example bellow
[Embed (source="728x90a.jpg" )]
public static const imgData1:Class;
Somewhere in your code, load the data into a visual component, like the example bellow
img1.source=imgData1;
The img1 is an Image component.
If you need to handle a large number of resources you can follow these 3 steps:
If you choose a different method that involves loading external files be aware that some flash game websites require the games they host to be contained within a single swf file.