media @ VU
flex-draw.mx
flex-draw.mx
(swf
)
[ flash
]
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
width="600" height="400"
horizontalAlign="center" verticalAlign="middle"
viewSourceURL="@mx-draw.html"
>
<mx:Script>
<![CDATA[
import flash.events.MouseEvent;
private function clickHandler ( event:MouseEvent ):void
{
myLabel.text = "你好";
init();
}
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.events.MouseEvent;
private var _colorPallet:Array = [0xFFFFFF, 0xFF0000, 0xFF00, 0xFF, 0];
private var _colorListeners:Array = [onWhite, onRed, onGreen, onBlue, onBlack];
private var _currentColor:uint = 0;
private var _paper:Sprite;
public function init():void {
stage.align = StageAlign.TOP_LEFT;
createPaper();
createPallet();
}
private function createPaper():void {
var _paper:Sprite = new Sprite();
_paper.graphics.beginFill(0xDDDDDD, 1);
_paper.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
_paper.addEventListener(MouseEvent.MOUSE_DOWN, onBeginDraw);
_paper.addEventListener(MouseEvent.MOUSE_UP, onEndDraw);
addChild(_paper);
}
private function createPallet():void {
for(var i:int = 0; i < _colorPallet.length; i++) {
var s:Sprite = new Sprite();
s.graphics.beginFill(_colorPallet[i], 1);
s.graphics.drawCircle(20, 25 * i + 10, 10);
s.buttonMode = true;
s.useHandCursor = true;
s.addEventListener(MouseEvent.CLICK, _colorListeners[i]);
addChild(s);
}
}
private function onBeginDraw(e:MouseEvent):void {
e.target.graphics.endFill();
e.target.graphics.moveTo(mouseX, mouseY);
e.target.graphics.lineStyle(5, _currentColor, 1);
e.target.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
}
private function onEndDraw(e:MouseEvent):void {
e.target.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
}
private function onMouseMove(e:MouseEvent):void {
e.target.graphics.lineTo(mouseX, mouseY);
}
private function onWhite(e:MouseEvent):void {
_currentColor = 0xFFFFFF;
}
private function onRed(e:MouseEvent):void {
_currentColor = 0xFF0000;
}
private function onGreen(e:MouseEvent):void {
_currentColor = 0xFF00;
}
private function onBlue(e:MouseEvent):void {
_currentColor = 0xFF;
}
private function onBlack(e:MouseEvent):void {
_currentColor = 0;
}
]]>
</mx:Script>
<mx:Panel
title="!你好" horizontalAlign="center"
paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10"
>
<mx:Label id="myLabel" width="180" fontWeight="bold" fontSize="24"/>
<mx:Button id="myButton" label="打我!" click="clickHandler(event);" />
</mx:Panel>
</mx:Application>
(C) A. Eliëns
2/9/2007
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.
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2780434-1";
urchinTracker();
</script>