问题描述
我在创建一个新的进程 - 精简版 - 的版本,我创建了一个,而前一个Flex应用程序。我一直在移植了很多类和组件到一个Flex库项目是编译的SWC文件。因为两者都是凯恩戈姆应用程序,我不能完全消除重复code,但它似乎是合乎逻辑,我应该能够分享资产 - 如图标(PNG文件)。什么是做到这一点的最好方法是什么?我曾尝试包括他们在深港西部通道,但我无法弄清楚如何访问它们的应用程序。如果你能帮助我明白这一点,那么我的问题将得到解答。有什么想法?
I am in the process of creating a new - "lite" - version of a Flex application I created a while ago. I have been porting over many of the Classes and Components to a Flex Library Project that compiles an SWC file. Because both are Cairngorm applications, I'm not able to completely eradicate duplicate code, but it seems logical that I should be able to share assets - such as icons (PNG files). What is the best way to do this? I have tried including them in the SWC, but I can't figure out how to access them in the application. If you can help me figure that out, then my question will be answered. Any thoughts?
下面是和示例如何我现在嵌入图标/在我的Flex应用程序中的图像:
Here is and example of how I currently embed icons/images in my Flex application:
<mx:Script>
<![CDATA[
[Bindable]
[Embed(source="assets/icons/cancelIcon.png")]
private var cancelIcon:Class;
[Bindable]
[Embed(source="assets/icons/saveIcon.png")]
private var saveIcon:Class;
]]>
</mx:Script>
感谢。
推荐答案
0)首先,着眼于code以上 - 我推荐一些细微的变化:
0) First, looking at the code above - I recommend some minor changes:
// Actionscript instead of MXML:
public class ResourceClasses
{
Bindable]
[Embed(source="assets/icons/cancelIcon.png")]
public static var CancelIconClass:Class;
// make your variable public and static without public no one
// outside the class can access AND bindable won't matter
}
----现在,编译库。----如果资产不是在正确的地方,编译器会抱怨
---- Now, compile your library.---- If the assets aren't in the right place the compiler will complain
1)在你的应用程序,你需要引用库项目/ SWC
1) In your application, you need to reference the library project / swc
----你应该能够得到code提示/智能感知在Flex Builder /月食从类在应用程序中的类在库项目
---- You should be able to get code hints / intellisense in Flex Builder / eclipse from classes in your Application to classes in the library project
2)在您的应用程序 - 做一些code是这样的:
2) In your Application - Do some code like this:
var image:Image = new Image();
image.source = ResourceClasses.CancelIconClass;
// more image property setting...
someCanvas.addChild(image);
3)这将让你去 - 用库项目来保存图像等...
3) This will get you going - using a Library project to hold images, etc...
*** DO注:如果图像需要加载多次,重复使用等 - 还有其他的步骤来压榨出最佳的性能,等等...
*** DO NOTE: If the images need to be loaded multiple times, reused, etc -- There are other steps to take to squeeze out the best performance, etc...
这篇关于什么是分享资产的最好方式 - 图标/图片 - 多个Flex应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!