浏览 1111 次
该帖已经被评为隐藏帖
|
|
---|---|
作者 | 正文 |
发表时间:2009-03-17
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()"> <mx:Canvas x="29" y="145" width="661" height="362"> <mx:Canvas id="canvas_1" x="118" y="30" width="457" height="117" backgroundColor="#F0E6E6"> <mx:Image id="hair" x="150" y="32" source="../images/hair_1_0.gif"/> </mx:Canvas> <mx:Canvas id="canvas_2" x="118" y="175" width="457" height="185" borderColor="#B2BCC3" backgroundColor="#B1D6F6" horizontalScrollPolicy="off" verticalScrollPolicy="off"> </mx:Canvas> </mx:Canvas> <mx:Script> <![CDATA[ import mx.controls.Image; import mx.core.DragSource; import mx.managers.DragManager; import mx.events.DragEvent; private var sp_1:Sprite; private var sp_2:Sprite; private var del_per:Number=0.3; private var del_alpha:Number = 0.1; internal function init():void { sp_1 = new Sprite(); sp_1.graphics.lineStyle(3,0x243435,1); sp_1.graphics.beginFill(0x556433,0.5); sp_1.graphics.drawCircle(40,40,40); sp_1.graphics.endFill(); this.canvas_2.rawChildren.addChild(sp_1); sp_1.addEventListener(MouseEvent.MOUSE_DOWN,spDownHandler); } /***=========移动sprite============****/ private function spDownHandler(e:MouseEvent):void { sp_1.startDrag(); sp_1.addEventListener(MouseEvent.MOUSE_UP,spUpHandler); sp_1.addEventListener(MouseEvent.MOUSE_MOVE,spMoveHandler); } private function spMoveHandler(e:MouseEvent):void { var sp:Sprite = Sprite(e.currentTarget); /**横向判断**/ if(sp.x<(0-sp.width+sp.width*del_per)) { sp.alpha=del_alpha; } else if(sp.x>(this.canvas_2.width-sp.width*del_per)) { sp.alpha=del_alpha; } else if(sp.y<(0-sp.height+sp.height*del_per)) {/**纵向判断**/ sp.alpha=del_alpha; } else if(sp.y>(this.canvas_2.height-sp.height*del_per)) { sp.alpha=del_alpha; } else { sp.alpha=1; } } private function spUpHandler(e:MouseEvent):void { var sp:Sprite = Sprite(e.currentTarget); sp_1.stopDrag(); sp_1.removeEventListener(MouseEvent.MOUSE_UP,spUpHandler); sp_1.removeEventListener(MouseEvent.MOUSE_MOVE,spMoveHandler); if(sp.alpha<=del_alpha) { sp.graphics.clear(); sp = null; } } ]]> </mx:Script> </mx:Application> 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |