开发者

Accessing a canvas created in another function?

开发者 https://www.devze.com 2022-12-29 16:59 出处:网络
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.

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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号