Actionscript add strings to embedded images?

送分小仙女□ 提交于 2020-01-13 19:24:36

问题


Say I have something like this:

[Embed(source='../lib/images/image01.png')] var Image:Class

But I want to change that images based on another string like so:`

var StringData:String
StringData = "02";
[Embed(source='../lib/images/image'+ StringData +'.png')] var Image:Class

But this gives me an error, is there another way to do something like this?


回答1:


Embedded resources are evaluated at compiling time so you can't set a dynamic path.

If you want a unique path by compile type (debug / release for exemple), you can use compiler variables :

[Embed(source=CONFIG::ICON_PATH)]
var Image:Class;

And add compiler args:

-define+=CONFIG::ICON_PATH,'../lib/images/image01.png'

or

-define+=CONFIG::ICON_PATH,'../lib/images/image02.png'


来源:https://stackoverflow.com/questions/5973145/actionscript-add-strings-to-embedded-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!