Category Archives: one-liners

new BitmapData() One-Liner

Actionscript:
  1. Bitmap(addChild(new Bitmap(new BitmapData(100,100,false,0x000000)))).bitmapData.fillRect(new Rectangle(10,10,10,10), 0xFF0000);

Also posted in BitmapData | Tagged , | Leave a comment

new Sprite() One-liner

Actionscript:
  1. 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.

Also posted in instantiation | Tagged | Leave a comment

XOR Color Invert

Actionscript:
  1. var yellow:uint = 0xFFFF00;
  2.  
  3. // draws yellow circle
  4. with(graphics) beginFill(yellow), drawCircle(100,100,50);
  5.  
  6. // invert the color using XOR assignment
  7. // yellow becomes 0x0000FF
  8. yellow ^= 0xFFFFFF;
  9.  
  10. // draws blue  circle
  11. with(graphics) beginFill(yellow), drawCircle(200,100,50);

Just a fun use for XOR. You could also do it without XOR assignment:

Actionscript:
  1. 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:

Actionscript:
  1. trace((0x543210 ^ 0xFFFFFF).toString(16));

If you'd like to read about bitwise operators, I recommend wikipedia's article.

Also posted in Operators | Tagged , , | Leave a comment