O'Reilly Hacks
oreilly.comO'Reilly NetworkSafari BookshelfConferences Sign In/My Account | View Cart   
Book List Learning Lab PDFs O'Reilly Gear Newsletters Press Room Jobs  


 
Buy the book!
Flash Hacks
By Sham Bhangal
June 2004
More Info

HACK
#15
Create Synthetic Art
Instead of downloading large bitmaps or creating predetermined layouts, make Flash generate artwork on the fly

[Discuss (0) | Link to this hack]

The following code generates a 12 8 grid of our node clips whenever the user clicks on the Stage and makes each copy go to and stop at a random frame number:

this.onMouseDown = function( ) {
  var depth = 0;
  for (var i = 0; i < 12; i++) {
    for (var j = 0; j < 8; j++) {
      var me = "n" + i + j;
      this.attachMovie("node", me, depth++);
      this[me]._x = 50 * i;
      this[me]._y = 50 * j;
      this[me].gotoAndStop(random(100) + 1);
    }
  }
};

To make our pattern appear more complex, we can nest further copies of node into the pattern. Each copy of node contains the following code:

if (Math.ceil(Math.random( ) < 0.80)) {
  this.attachMovie("node", "n", 0);
  this["n"]._x = 50*i;
  this["n"]._y = 50*j;
  this["n"]._xscale = n._yscale = _parent._xscale / 1.5;
  this["n"].gotoAndStop(Math.ceil((Math.random( )*10)));
}


O'Reilly Home | Privacy Policy

© 2007 O'Reilly Media, Inc.
Website: | Customer Service: | Book issues:

All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.