[AS3]as3鼠标事件startDrag的一个用法实例
[AS3]as3鼠标事件startDrag的一个用法实例,as3鼠标,as3鼠标事件
[AS3]as3鼠标事件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)跨平台技术(HLSPlayer,m3u8Player跨平台多终端)
- DiscuzX3.2酷播视频插件(dz论坛自定义视频插件带广告
- [微信视频]实现网站中的视频在微信平台上正常播放(超多组图)
- [rtsp]海康威视监控摄像头实现web端无插件监控实拍效果
- 很酷,酷播wordpress视频插件(支持PC/安卓/苹果跨平台播放)
- [组图]微信视频技术:支持微信视频直播和视频点播
- [AS3]as3.0的rtmp流媒体播放器写法源代码示例
- 一步一步教你制作FLV网页视频播放器
请稍候...