topical media & game development
student-mma-16-Annotation.mx
student-mma-16-Annotation.mx
[swf]
flex
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" backgroundColor="0xFFFFFF"
mouseDown="onMouseDown()" mouseUp="onMouseUp()">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
private var thickness:int = 5;
private var fromX:int;
private var fromY:int;
private var toX:int;
private var toY:int;
private var line:Shape = new Shape();
private function onMouseDown():void {
line.graphics.lineStyle(thickness, 0x000000);
fromX = mouseX;
fromY = mouseY;
addEventListener(Event.ENTER_FRAME, drawLine);
}
private function drawLine(e:Event):void {
if(fromX != mouseX || fromY != mouseY) {
line.graphics.moveTo(fromX, fromY);
toX = (mouseX > this.width ? this.width : (mouseX < 0 ? 0 : mouseX));
toY = (mouseY > this.height ? this.height : (mouseY < 0 ? 0: mouseY));
line.graphics.lineTo(toX, toY);
this.rawChildren.addChild(line);
fromX = toX;
fromY = toY;
}
}
public function onMouseUp():void {
removeEventListener(Event.ENTER_FRAME, drawLine);
}
]]>
</mx:Script>
</mx:Canvas>
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.