我已经在网上试图找到解决方案,但一切似乎都是以mxml为中心的。我想要的是动态创建一系列Graphics对象,每个对象都有一个子BitmapImage。但是,这似乎不起作用:
var bmi:BitmapImage = new BitmapImage();
bmi.source="@Embed('custom-case.png')";
var gr:Graphic = new Graphic( );
gr.addElement( bmi );
gr.x = 50;
gr.y = 50;
this.addElement( gr );
然而,这样做:
<s:Graphic x="250" y="250">
<s:BitmapImage source="@Embed('custom-case.png')">
</s:BitmapImage>
</s:Graphic>
提前感谢任何想法。
保
答案 0 :(得分:4)
在AS3中完全不同,你必须定义一个变量类类型,如下所示。
[Embed("custom-case.png")]
private var someImage:Class;
...
bmi.source=someImage;
答案 1 :(得分:0)
跟进Shruti的评论/问题(由于我目前的声誉不足,我无法发表评论):
使用mxml动态更新图像的要求与原始答案所示的相同,即您可能想要动态更改的任何图像必须预先嵌入mxml中:
[Embed(source="image.png")] private var theImage:Class;
以后可以用来更新图像源:
<fx:Script>
<![CDATA[
[Embed(source="image.png")] private var theImage:Class;
private function updateImage():void {
image.source = theImage;
}
]]>
</fx:Script>
<s:BitmapImage id="image" source="@Embed('defaultImage.png')"/>