您的位置:首页 > 其它

Flex3学习轨迹:显示简单的动态鼠标

2012-03-08 16:34 363 查看
当鼠标移动到Panel容器的上方的时候,出发了MouseOver事件,然后利用CursorManager类的setCursor()方法来设置鼠标指针。分别显示圆形、矩形、椭圆形、圆边矩形的类。这些类必须继承自flash.display.Sprite基类。绘制圆形的AS代码:
package cursors{import flash.display.Sprite;public class Circle extends Sprite{public function Circle(){this.graphics.lineStyle( 1 , 0x000000 , 1 );this.graphics.drawCircle( 0 , 0 , 10 );super();}}}
绘制椭圆形:
package cursors{import flash.display.Sprite;public class Ellipse extends Sprite{public function Ellipse(){this.graphics.lineStyle( 1 , 0x000000 , 1 );this.graphics.drawEllipse( 0 , 0 , 50 , 10 );super();}}}
绘制矩形:
package cursors{import flash.display.Sprite;public class Rect extends Sprite{public function Rect(){this.graphics.lineStyle( 1 , 0x000000 , 1 );this.graphics.drawRect( 0 , 0 , 40 , 15);super();}}}
绘制圆边矩形:
package cursors{import flash.display.Sprite;public class RoundRectComplex extends Sprite{public function RoundRectComplex(){this.graphics.lineStyle( 1 , 0x000000 , 1 );this.graphics.drawRoundRectComplex( 0 , 0 , 45 , 25 , 5 , 0 , 0 , 5 );super();}}}
主程序代码:
<?xml version="1.0" encoding="utf-8"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" fontSize="12" ><mx:Script><![CDATA[import cursors.*;import mx.managers.CursorManager;private function setCursor(cursorClass:Class = null):void{CursorManager.setCursor(cursorClass);}private function clearCursor():void{CursorManager.removeAllCursors();}]]></mx:Script><mx:Panel title="显示简单动态鼠标指针" width="360" height="280"verticalAlign="middle" horizontalAlign="center"><mx:Tile horizontalGap="10" verticalGap="10"><mx:Panel title="圆形指针" mouseOver="setCursor(Circle);"mouseOut="clearCursor();" height="100" width="150"/><mx:Panel title="椭圆指针" mouseOver="setCursor(Ellipse);"mouseOut="clearCursor();" height="100" width="150"/><mx:Panel title="矩形指针" mouseOver="setCursor(Rect);"mouseOut="clearCursor();" height="100" width="150"/><mx:Panel title="圆边矩形指针" mouseOver="setCursor(RoundRectComplex);"mouseOut="clearCursor();" height="100" width="150" /></mx:Tile></mx:Panel></mx:Application>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: