在actionscript中动态创建一个类
我先把问题提出来。 我需要从外部加载我在项目中使用的所有图像而不嵌入。 这些图像要么以皮肤的形式出现,要么以树中项目的图标的形式出现。 我在此处遇到了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
完成这些事情最简单的事情是创建一个/多个包含您的资源的 swf,加载它,然后从那里提取类(即从加载的 swfs 应用程序域)...
对此有多种解决方案
希望有帮助
编辑:第二个解决方案是在服务器上创建资产,使用合适的工具...或自己编写工具,但是这更像是一个笑话...:) ...我意识到,到flex编译器的链接是错误的...这个想法就是简单地将它插入到您的Web服务器中,然后让它编译一些ActionScript, '将进行嵌入...因此您将生成一个如下所示的 ActionScript 文件:
然后让 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:
ByteArray
s using URLLoader, and then creating a newByteArray
, 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 ...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:
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
这个就是我一直在寻找的......不幸的是作者声称他无法将其用于按钮皮肤
This was what I was looking for ... Unfortunately the author claims he was not able to use it for button skins