[AS3]as3拖拽用法(MouseEvent的和startDrag的方式)
[AS3]as3拖拽用法(MouseEvent的和startDrag的方式)
[AS3]as3拖拽用法(MouseEvent的和startDrag的方式)
- package
- {
- import com.ui.Ball;
- import com.ui.Ship;
- import flash.display.Sprite;
- import flash.events.MouseEvent;
- public class Main extends Sprite
- {
- private var ball:Ball;
- public function Main():void
- {
- init();
- }
- private function init():void
- {
- ball = new Ball();
- ball.x = 100;
- ball.y = 100;
- this.addChild(ball);
- ball.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
- }
- private function onMouseDown(event:MouseEvent):void
- {
- stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
- stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
- }
- private function onMouseUp(event:MouseEvent):void
- {
- stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
- stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
- }
- private function onMouseMove(event:MouseEvent):void
- {
- ball.x = this.mouseX + (this.mouseX - ball.x);
- ball.y = this.mouseY + (this.mouseY - ball.y);
- }
- }
- } package{
- import com.ui.Ball;
- import com.ui.Ship;
- import flash.display.Sprite;
- import flash.events.MouseEvent;
- public class Main extends Sprite
- {
- private var ball:Ball;
- public function Main():void
- {
- init();
- }
- private function init():void
- {
- ball = new Ball();
- ball.x = 100;
- ball.y = 100;
- this.addChild(ball);
- ball.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
- }
- private function onMouseDown(event:MouseEvent):void
- {
- ball.startDrag();
- stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
- }
- private function onMouseUp(event:MouseEvent):void
- {
- ball.stopDrag();
- }
- }
- }
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...