EDIT: I just needed to add: import mx.controls.Image;
I have an MXML file, and when I can add image tags to the XML and it works.
But, I can’t figure out how to create an image and add it to the canvas programatically with 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
addChildfunction on the MXML component you wish to add the Image to. For example:MXML:
ActionScript:
This is a nice example on how to use the addChild function.