Created
July 9, 2009 20:37
-
-
Save brentp/143980 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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