Actionscript:
-
// draw red circle
-
with (graphics) beginFill(0xFF0000), drawCircle(200,100,30);
-
-
// draw 100 gray circles
-
with (graphics) for (var i:int = 0; i<100; i++) beginFill(0x666666), drawCircle(Math.random()*200, Math.random()*200, Math.random()*10), endFill();
-
-
// draw a few lines
-
with (graphics) lineStyle(0, 0x000000), moveTo(10,210), lineTo(20,300), lineTo(30,210), lineTo(40,300), lineTo(50,210), lineTo(60,300);
Sometimes it's tedious to write lines and lines of Graphics class method calls. Using a with statement you can reduce these calls into one long (not very readable) line of code.
More readable example:
Actionscript:
-
with(graphics) {
-
beginFill(0xFF0000);
-
drawRect(0,0,100,100);
-
endFill();
-
beginFill(0xFFFF00);
-
drawRect(10,10,80,80);
-
endFill();
-
beginFill(0x0000FF);
-
drawCircle(50,50,40);
-
}
2 Comments
Yes, I also use with(graphics) a lot, { } blocking makes the code more readable.
What’s a bit pity that - at least Flash CS3 API - doesn’t show the code hints inside with(){}
yeah, that would be nice. One reason is because the CS3/CS4 editors use the dot operator to show the code hinting…