在actionscript中动态创建一个类

发布于 2024-07-27 17:12:51 字数 296 浏览 2 评论 0原文

我先把问题提出来。 我需要从外部加载我在项目中使用的所有图像而不嵌入。 这些图像要么以皮肤的形式出现,要么以树中项目的图标的形式出现。 我在此处遇到了 IconUtility 类 我能够修改它并将其用于树,但问题是我们不能使用同一组件的 iconutility 来设置 2 个不同的皮肤(例如按钮 - 上皮肤下皮肤)。 我无法想到 iconutility 的解决方法。 是否可以模拟嵌入并动态创建一个类并在运行时返回该类?

Let me present the problem first.
I need to load all images that I have used in my project externally without embedding.
The images are present either in skins or as icons for items in trees.
I came across the IconUtility class here
I was able to modify it and use it for trees but the problem is we cannot use iconutility for the same component to set 2 different skins (like for a button - upskin downskin).
I was not able to think of a workaround with iconutility.
Is it possible to simulate embed and create a class dynamically and return the class at runtime?

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

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

发布评论

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

评论(2

橘和柠 2024-08-03 17:12:51

完成这些事情最简单的事情是创建一个/多个包含您的资源的 swf,加载它,然后从那里提取类(即从加载的 swfs 应用程序域)...

对此有多种解决方案

  • :版本是使用 URLLoader 将这些图像加载到 ByteArray 中,然后创建一个新的 ByteArray,这将是一个 swf 文件,包含嵌入的资源和必要的指令将它们与类链接...您可能想看看spark的 swfassist ...
  • 更简单和高效一点(因为您只执行一次),就是在服务器上执行此操作...在这里您可以
  • 简单地使用 flex 编译器
  • 使用 swfmill
  • 使用一些库来操作 swf,例如 ming
  • 自己动手...:)

希望有帮助

编辑:第二个解决方案是在服务器上创建资产,使用合适的工具...或自己编写工具,但是这更像是一个笑话...:) ...我意识到,到flex编译器的链接是错误的...这个想法就是简单地将它插入到您的Web服务器中,然后让它编译一些ActionScript, '将进行嵌入...因此您将生成一个如下所示的 ActionScript 文件:

package {
    import flash.display.Sprite;
    import flash.utils.describeType;
    public class Assets extends Sprite {
        [Embed(source='asset_1_Location')]
        public static var asset_1:Class;
        [Embed(source='asset_2_Location')]
        public static var asset_2:Class;
        ...
        [Embed(source='asset_n_Location')]
        public static var asset_n:Class;    
        public function Assets() { }
        public static function getAll():Object {
            var ret:Object = { };
            for each (var x:XML in describeType(Assets).variable.(@type=="Class")) {
                var name:String =  x.@name;
                ret[name] = Assets[name];
            }
            return ret;
        }
    }
}

然后让 Flex 编译器对其进行编译...加载后,使用 LoaderInfo::applicationDomain.getDefinition("Assets").getAll() 提取数据,这将为您提供一个包含所需所有类的键值映射...

使用其他工具,它的工作方式会有所不同,但我希望这能澄清它应该如何工作...

在服务器上,您需要一项服务,它将为您构建这些资产 swf,并缓存它们...所以您发送一些 POST 请求,例如使用您需要的文件/图像的 JSON 数组,它会返回 swf...服务器应该做当然适当的缓存...

希望,现在它有帮助...:)

greetz

back2dos

the most simple thing to accomplish these things is to create one/multiple swfs containing your assets, load it, and then pull out the classes from there (i.e. from the loaded swfs application domain) ...

there are multiple solutions to that:

  • hardcore version is to load those images into ByteArrays using URLLoader, and then creating a new ByteArray, that'll be an swf file, containing the embedded assets and the necessary instructions to link them with classes ... you might wanna have a look at spark's swfassist ...
  • a little more simpler and performant (since you only do this once), is to do that on the server ... here you could
  • simply use the flex compiler
  • use swfmill
  • use some libraries for manipulating swf, like ming
  • do it yourself, by hand ... :)

hope that helps

edit: the second solution is about creating assets on the server, using a suitable tool ... or coding the tool yourself, but that was more of a joke ... :) ... i realized, the link to the flex compiler was wrong ... the idea would be to simply plug it into your web server, and then have it compile some ActionScript, that'll do the embed ... so you would generate one ActionScript file like this:

package {
    import flash.display.Sprite;
    import flash.utils.describeType;
    public class Assets extends Sprite {
        [Embed(source='asset_1_Location')]
        public static var asset_1:Class;
        [Embed(source='asset_2_Location')]
        public static var asset_2:Class;
        ...
        [Embed(source='asset_n_Location')]
        public static var asset_n:Class;    
        public function Assets() { }
        public static function getAll():Object {
            var ret:Object = { };
            for each (var x:XML in describeType(Assets).variable.(@type=="Class")) {
                var name:String =  x.@name;
                ret[name] = Assets[name];
            }
            return ret;
        }
    }
}

then have the flex compiler compile it ... when loaded, extract data with LoaderInfo::applicationDomain.getDefinition("Assets").getAll(), which will give you a key-value map with all the classes needed ...

with other tools, it would work differently, but i hope this clarifies, how it should work ...

on the server, you need a service, that will build these asset swfs for you, and cache them ... so you send up some POST request, for example with a JSON array of files/images you need, and it'll give you back the swf ... the server should do appropriate caching of course ...

hope, now it helps ... :)

greetz

back2dos

巷子口的你 2024-08-03 17:12:51

这个就是我一直在寻找的......不幸的是作者声称他无法将其用于按钮皮肤

This was what I was looking for ... Unfortunately the author claims he was not able to use it for button skins

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