[英]How can I add an image to my Flex application at with ActionScript?
EDIT: I just needed to add: import mx.controls.Image; 编辑:我只需要添加:import mx.controls.Image;
I have an MXML file, and when I can add image tags to the XML and it works. 我有一个MXML文件,可以将图像标签添加到XML并可以正常工作。
But, I can't figure out how to create an image and add it to the canvas programatically with AS. 但是,我无法弄清楚如何创建图像并使用AS将其以编程方式添加到画布中。
I was hoping this would have worked: 我希望这能奏效:
var card:Image = new Image(); //ERRORS ON THIS LINE: call to possibly undefined method Image.
card.width = cardHeight;
card.height = cardWidth;
card.x = xCoord;
card.y = yCoord;
Thanks for your help! 谢谢你的帮助!
You need to call the addChild
function on the MXML component you wish to add the Image to. 您需要在要将图像添加到的MXML组件上调用
addChild
函数。 For example: 例如:
MXML: MXML:
<mx:Canvas id="mxmlComponent" />
ActionScript: 动作脚本:
private function some_function() : void
{
var card:Image = new Image();
card.width = cardHeight;
card.height = cardWidth;
card.x = xCoord;
card.y = yCoord;
mxmlComponent.addChild(card);
}
This is a nice example on how to use the addChild function. 这是有关如何使用addChild函数的一个很好的示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.