在 ActionScript 3 嵌入语句中使用变量
我在名为 asset/images/pieces 的目录中有一组图像,名为 1.png、2.png 3.png 等。我的问题是,如何使用 Action Script 3 中的随机变量加载这些图像?
我可以执行下面输入的操作吗?
/** Typical Embed Statement **/
[Embed(source="image/path/here")]
/** Modified **/
var path_name = "image/path/here/";
[Embed(source=path_name)]
I have a set of images within a directory called assets/images/pieces named 1.png, 2.png 3.png etc. My question is, how can I load these images using a random variable within Action Script 3?
Could I do what I have entered below?
/** Typical Embed Statement **/
[Embed(source="image/path/here")]
/** Modified **/
var path_name = "image/path/here/";
[Embed(source=path_name)]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的理解是你不能这样做,因为嵌入标签在编译时执行,所以 path_name 还没有分配给它的值,你会得到一个错误:
要在运行时处理嵌入,你可能必须使用 URLLoader。但请记住,它是异步的,您必须等待 COMPLETE 事件才能使用图像。
http://help.adobe.com/en_US /FlashPlatform/reference/actionscript/3/flash/net/URLLoader.html
My understaning is that you can't do it because the Embed Tag executes at compile time so path_name doesn't have a values assigned to it yet and you will get an error:
To handle the embed at run-time you will probably have to use URLLoader. But keep in mind it is asynchronous and you will have to wait for a COMPLETE event before being able to use the image.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLLoader.html