Apache flex 如何使用ActionScript将图像添加到我的Flex应用程序?
编辑:我只需要添加:import mx.controls.Image强> 我有一个MXML文件,当我可以向XML中添加图像标记时,它就可以工作了 但是,我不知道如何创建一个图像并使用AS以编程方式将其添加到画布 我希望这能奏效:Apache flex 如何使用ActionScript将图像添加到我的Flex应用程序?,apache-flex,flash,flex3,Apache Flex,Flash,Flex3,编辑:我只需要添加:import mx.controls.Image 我有一个MXML文件,当我可以向XML中添加图像标记时,它就可以工作了 但是,我不知道如何创建一个图像并使用AS以编程方式将其添加到画布 我希望这能奏效: var card:Image = new Image(); //ERRORS ON THIS LINE: call to possibly undefined method Image. card.width = cardHeight; card.height = card
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;
谢谢你的帮助 您需要在要将图像添加到的MXML组件上调用
addChild
函数。例如:
MXML:
这是关于如何使用addChild函数的示例。这里有错误:var card:Image=new Image()//行:调用可能未定义的方法Image。您可能需要在脚本的开头添加“import mx.controls.Image”。这些只是代码片段,您可以理解它们,而不是一个正常工作的应用程序
<mx:Canvas id="mxmlComponent" />
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);
}