Abdulcode

Pages

Aug 18, 2010

AS3 : with keyword

It can be used to write cleaner code when setting multiple properties of the same object.

Normal Code:
var circle:Sprite = new Sprite();
circle.graphics.beginFill(0xFFCC00);
circle.graphics.drawCircle(100,100,50);
circle.graphics.endFill();
addChild(circle);


Using with keyword Code:
var circle:Sprite = new Sprite();
with (circle.graphics)
{
beginFill(0xFFCC00);
drawCircle(100, 100, 50);
endFill();
}
addChild(circle);

No comments:

Post a Comment