[AS3]as3下获取当前坐标值代码写法示例
使用DisplayObject实例的只读属性mouseX和mouseY检查鼠标相对位置,或者MouseEvent事件的localX和localY属性
使用DisplayObject实例的只读属性mouseX和mouseY检查鼠标相对位置,或者MouseEvent事件的localX和localY属性
- package {
- import flash.display.Sprite;
- import flash.events.MouseEvent;
- import flash.text.TextField;
- import flash.text.TextFieldAutoSize;
- [SWF(backgroundColor="#004D84")]
- public class Sample1209 extends Sprite
- {
- private var lblMain:TextField;
- private var lblSub:TextField;
- private var rect:Sprite;
- public function Sample1209()
- {
- this.lblMain = new TextField();
- lblMain.autoSize = TextFieldAutoSize.CENTER;
- this.addChild(lblMain);
- this.lblSub = new TextField();
- lblSub.autoSize = TextFieldAutoSize.CENTER;
- lblSub.y = 40;
- this.addChild(lblSub);
- this.rect = new Sprite();
- rect.graphics.beginFill(0xFFFF00);
- rect.graphics.drawRect(0,0,200,100);
- rect.graphics.endFill();
- rect.addEventListener(MouseEvent.MOUSE_MOVE,rect_OnMouseMove);
- rect.x = 30;
- rect.y = 60;
- this.addChild(rect);
- }
- private function rect_OnMouseMove(event:MouseEvent):void
- {
- this.lblMain.text = "cuplayer.com提示stage里的X是:"
+Math.round(this.mouseX)+",Y是:"+Math.round(this.mouseY);- this.lblSub.text = "sprite里的X是:"
+Math.round(this.rect.mouseX)+",Y是:"+Math.round(this.rect.mouseY);- //cuplayer.com提示this.lblSub.text = "sprite里的X是:"
+Math.round(event.localX)+",Y是:"+Math.round(event.localY);- }
- }
- }
热门文章推荐
- [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示例
请稍候...