// Written by Chloe Fan // Based on Brush.as // July 2008 package { import flash.display.MovieClip; import flash.display.Sprite; import flash.geom.ColorTransform; import flash.geom.Rectangle; import org.wiiflash.Wiimote; import org.wiiflash.IR; import org.wiiflash.events.ButtonEvent; import org.wiiflash.events.WiimoteEvent; import flash.display.Graphics; public class HelperBrush extends MovieClip { public var brush:Square = new Square();// instance of dot movieclip private var size:int = 12; private var color:uint = 0x000000; private var lockedStroke:Sprite; public var locked:Boolean = false; public function HelperBrush() { addChild(brush); } /////////////////////////////////////////////////////////////////////// // onRefresh // /////////////////////////////////////////////////////////////////////// public function onRefresh(e:WiimoteEvent):void { // update brush brush.width = size; brush.height = size; // get IR position var wiix = 1 - e.target.ir.x1;// x goes from 1-0 var wiiy = e.target.ir.y1;// y goes from 0-1 // update brush position if (wiix >= 0 && wiix <= 800 && wiiy >= 0 && wiiy <= 600) { brush.x = wiix * 800; brush.y = wiiy * 600; } else { if (brush.x/2 < 0 && wiix < 0) { brush.x = 0; } if (brush.x/2 > 800) { brush.x = 800; } if (wiiy < 0) { brush.y = 0; } if (wiiy > 600) { brush.y = 600; } } } /////////////////////////////////////////////////////////////////////// // Lock/unlock or Draw/stopDraw // /////////////////////////////////////////////////////////////////////// /* public function lock(e:ButtonEvent):void { // if brush is intersecting stroke/shape, then access that stroke and lock it to brush for each (stroke in strokes) { if (brush.hitTestObject(stroke)) { lockedStroke = stroke; distx = brush.x - lockedStroke.x; disty = brush.y - lockedStroke.y; locked = true; continue; } } } public function unlockOrStop(e:ButtonEvent):void { if (locked) { locked = false; } } */ } }