Accessing a canvas created in another function?
I created a canvas in a function, and in his function I have a CLICK eventlistener. On the click I want to manipulate what's inside the canvas.
Will referencing the canvas usin开发者_JS百科g the Dictionary class work?
You don't need a dictionary. Assuming that you added click listener using something like:
canvas.addEventListener(MouseEvent.CLICK, clickHandler);
you can access the canvas
inside the clickHandler
method using the event.currentTarget
property.
private function clickHandler(event:MouseEvent):void
{
//currentTarget is typed as object - cast it to canvas
var canvas:Canvas = Canvas(event.currentTarget);
//now do whatever you want with canvas
canvas.setStyle("backgroundColor", 0xffff00);
}
精彩评论