Bitmap(addChild(new Bitmap(new BitmapData(100,100,false,0x000000)))).bitmapData.fillRect(new Rectangle(10,10,10,10), 0xFF0000);
Browse the notebook
Category: one-liners
new Sprite() One-liner
var s:Sprite = Sprite(addChild(new Sprite()));
A way to make a new sprite, add it to the display list and store a reference to it.
Figured this out on my own… but have since seen it around on a few flash blogs here and there… thought it deserved a post.
XOR Color Invert
var yellow:uint = 0xFFFF00; // draws yellow circle with(graphics) beginFill(yellow), drawCircle(100,100,50); // invert the color using XOR assignment // yellow becomes 0x0000FF yellow ^= 0xFFFFFF; // draws blue circle with(graphics) beginFill(yellow), drawCircle(200,100,50);
Just a fun use for XOR. You could also do it without XOR assignment:
with(graphics) beginFill(yellow ^ 0xFFFFFF), drawCircle(200,100,50);
Playing a little with bitwise operators is a good way to make sure you understand them. Try tweaking this trace statement:
trace((0x543210 ^ 0xFFFFFF).toString(16));
If you’d like to read about bitwise operators, I recommend wikipedia’s article.