使用数组嵌入许多图形

发布于 2024-09-09 10:04:20 字数 578 浏览 8 评论 0原文

在 AS3 中,您可以将图形嵌入到类变量中:

     [Embed(source="MenuAssets.swf", symbol="topSquare")]
        public var TopMenuItem:Class;

我正在做的这个网站项目中有数百个资源,因此我想将资源嵌入到一个数组中以便快速访问。

我可以做这样的事情吗?它无法编译,所以我想知道它是否可能。

        public var MenuAssets:Array = [
           [Embed(source="MenuAssets.swf", symbol="topSquare")],
           [Embed(source="MenuAssets.swf", symbol="botSquare")],
           [Embed(source="MenuAssets.swf", symbol="leftSquare")],
           [Embed(source="MenuAssets.swf", symbol="rightSquare")],
        ]

In AS3 you can embed a graphic into a Class variable:

     [Embed(source="MenuAssets.swf", symbol="topSquare")]
        public var TopMenuItem:Class;

I have hundreds of assets in this one website project I'm doing, so I want to embed assets into an array for quick access.

Can I do something like this? Its not compiling so I'm wondering whether its possible.

        public var MenuAssets:Array = [
           [Embed(source="MenuAssets.swf", symbol="topSquare")],
           [Embed(source="MenuAssets.swf", symbol="botSquare")],
           [Embed(source="MenuAssets.swf", symbol="leftSquare")],
           [Embed(source="MenuAssets.swf", symbol="rightSquare")],
        ]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

空城缀染半城烟沙 2024-09-16 10:04:20

恐怕你不能。您可以执行以下操作:

public class Assets {
    [Embed(source="MenuAssets.swf", symbol="topSquare")]
    public static const TOP_SQUARE:Class;
    //... more assets ...
    public static function getAssets():Array {
        var ret:Array = [];
        for each (var s:String in describeType(Assets).constant.@name) ret.push(Assets[s]);
        return ret;
    }
}

I'm afraid you can't. What you could do is the following:

public class Assets {
    [Embed(source="MenuAssets.swf", symbol="topSquare")]
    public static const TOP_SQUARE:Class;
    //... more assets ...
    public static function getAssets():Array {
        var ret:Array = [];
        for each (var s:String in describeType(Assets).constant.@name) ret.push(Assets[s]);
        return ret;
    }
}
×眷恋的温暖 2024-09-16 10:04:20

您还可以将资产嵌入到单个 FLA 中。在 FLA 的库中,为每个类指定一个类名称,例如“graphics.menu.RightSquare”,然后将其导出为 SWC。配置 Flash Builder 项目以将 SWC 作为外部库加载。然后你可以做类似的事情:

import graphics.menu.*;

new RightSquare();

You could also embed the assets in a single FLA. In the FLA's library, give each one a class name like "graphics.menu.RightSquare" then export it as a SWC. Configure your Flash Builder project to load the SWC as an external library. Then you can do something like:

import graphics.menu.*;

new RightSquare();
温柔嚣张 2024-09-16 10:04:20

一般来说,Flex 中的元数据标签适用于类级别变量。

您必须使用[Embed] 元数据变量定义之前的标记,其中变量的类型为 Class。

但是您可以这样做:

[Embed(source="MenuAssets.swf", symbol="topSquare")]
public var TopMenuItem:Class;

[Embed(source="MenuAssets.swf", symbol="leftSquare")]
public var LeftMenuItem:Class;

[Embed(source="MenuAssets.swf", symbol="rightSquare")]
public var RightMenuItem:Class;

[Embed(source="MenuAssets.swf", symbol="botSquare")]
public var BottomMenuItem:Class;

public var menuAssets:Array = [TopMenuItem, LeftMenuItem, 
                               RightMenuItem, BottomMenuItem];

In general, the metadata tags in Flex apply to a class level variable.

You must use the [Embed] metadata tag before a variable definition, where the variable is of type Class.

You can however do:

[Embed(source="MenuAssets.swf", symbol="topSquare")]
public var TopMenuItem:Class;

[Embed(source="MenuAssets.swf", symbol="leftSquare")]
public var LeftMenuItem:Class;

[Embed(source="MenuAssets.swf", symbol="rightSquare")]
public var RightMenuItem:Class;

[Embed(source="MenuAssets.swf", symbol="botSquare")]
public var BottomMenuItem:Class;

public var menuAssets:Array = [TopMenuItem, LeftMenuItem, 
                               RightMenuItem, BottomMenuItem];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文