3

我正在创建我不久前创建的 Flex 应用程序的新“精简版”版本。我一直在将许多类和组件移植到编译 SWC 文件的 Flex 库项目中。因为两者都是 Cairngorm 应用程序,所以我无法完全消除重复代码,但我应该能够共享资产(例如图标(PNG 文件))似乎是合乎逻辑的。做这个的最好方式是什么?我已经尝试将它们包含在 SWC 中,但我不知道如何在应用程序中访问它们。如果你能帮我解决这个问题,那么我的问题就会得到解答。有什么想法吗?

以下是我目前如何在 Flex 应用程序中嵌入图标/图像的示例:

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

谢谢。

4

3 回答 3

4

0) 首先,看一下上面的代码——我建议做一些小的改动:

// 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
}

---- 现在,编译你的库。---- 如果资产不在正确的位置,编译器会抱怨

1)在你的应用程序中,你需要引用库项目/swc

---- 您应该能够在 Flex Builder/eclipse 中从您的应用程序中的类到库项目中的类中获取代码提示/智能感知

2) 在您的应用程序中 - 执行如下代码:

var image:Image = new Image();
image.source = ResourceClasses.CancelIconClass;

// more image property setting... 

someCanvas.addChild(image);

3)这会让你开始 - 使用图书馆项目来保存图像等......

*** 请注意:如果图像需要多次加载、重复使用等——还需要采取其他步骤来获得最佳性能等...

于 2009-06-10T03:29:55.563 回答
0

livedocs的这一部分对您来说会很有趣:

http://livedocs.adobe.com/flex/3/html/help.html?content=building_overview_5.html

你有一个具体的例子来说明你是如何嵌入资产并试图在不工作的结果 swc 中使用它们的吗?您认为您的问题在于将它们嵌入到 swc 中还是在实际应用程序中从 swc 中使用它们?

于 2009-06-09T17:54:09.873 回答
0

好吧,使用@Gabriel 的建议,这就是我最终得到的结果:

package
{
    [Bindable]
    public class ResourceClasses
    {
        [Embed(source="assets/icons/cross.png")]
        public static var CancelIconClass:Class;
    }
}

在我的应用程序中引用如下:

<?xml version="1.0" encoding="utf-8"?>
<mx:Box xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:Button label="Cancel Changes" icon="{ResourceClasses.CancelIconClass}" />
</mx:Box>

谢谢!

于 2009-06-10T15:06:45.420 回答