Skip to content

Instantly share code, notes, and snippets.

@brentp
Created July 9, 2009 20:37
Show Gist options
  • Save brentp/143980 to your computer and use it in GitHub Desktop.
Save brentp/143980 to your computer and use it in GitHub Desktop.
// build with: haxe swf9 fex.swf -main FlashExample
import flash.display.Sprite;
import flash.events.MouseEvent;
class FlashExample extends Sprite {
static function main(){
flash.Lib.current.addChild(new FlashExample());
}
public function new(){
super();
this.addBlocks();
}
public function addBlocks(){
for ( y in 0 ... 20 ){
for ( x in 0 ... 20 ) {
var b = new RBBlock();
b.x = x * 20;
b.y = y * 20;
this.addChild(b);
}
}
}
}
class RBBlock extends Sprite {
var color:Int;
static var red = 0xFF0000;
static var blue = 0x0000FF;
static var green = 0x00FF00;
public function new(){
super();
this.color = red;
this.addEventListener(MouseEvent.CLICK, onMouseClick);
this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
this.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
}
public function recolor(){
var g = this.graphics;
g.clear();
g.beginFill(this.color);
g.drawRect(0, 0, 15, 15);
g.endFill();
}
private function onMouseClick(e:MouseEvent){
this.color = (this.color == green) ? green : ( this.color == blue) ? red : blue;
this.recolor();
}
private function onMouseOver(e:MouseEvent){
this.color = this.color == green ? red: green;
this.recolor();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment