flash as3 鼠标事件的疑问
flashas3鼠标事件的疑问我在一个大的sprite上面放了个moiveclip,在moiveclip的类里面监听了mouse_move等事件,但是发现mouse_mo...
flash as3 鼠标事件的疑问 我在一个大的sprite上面放了个moiveclip,在moiveclip的类里面监听了mouse_move等事件,但是发现mouse_move总是跟不上鼠标!
我的代码如下:
package {
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
//import flash.display.Graphics;
public class linker extends MovieClip {
var sp:Sprite = new Sprite();
var x0=0;
var y0=0;
var flag=0;
public function linker() {
// constructor code
//gotoAndStop(2);
this.addEventListener(MouseEvent.MOUSE_MOVE,mousemove,false,100,true);
this.addEventListener(MouseEvent.MOUSE_DOWN,mousedown);
this.addEventListener(MouseEvent.MOUSE_UP,mouseup);
//this.addEventListener(MouseEvent.MOUSE_OUT,mousemove);
this.addChild(sp);
}
function mousemove(e:MouseEvent){
if(flag==1){
sp.graphics.lineStyle(2,0x00ff00);
sp.graphics.moveTo(x0,y0);
x0=e.localX;
y0=e.localY;
sp.graphics.lineTo(x0,y0);
}
}
function mousedown(e:MouseEvent){
flag=1;
trace(1);
}
function mouseup(e:MouseEvent){
flag=0;
trace(0);
sp.graphics..clear();
}
}
}
我想让鼠标单击moiveclip时,拖动鼠标开始画线,松开鼠标结束画线,但是总是失败,经常我已经松开鼠标了,mouse_up事件还是没有反应;经常我拖动画线的时候mouse_move断掉!请帮帮忙! 展开
我的代码如下:
package {
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
//import flash.display.Graphics;
public class linker extends MovieClip {
var sp:Sprite = new Sprite();
var x0=0;
var y0=0;
var flag=0;
public function linker() {
// constructor code
//gotoAndStop(2);
this.addEventListener(MouseEvent.MOUSE_MOVE,mousemove,false,100,true);
this.addEventListener(MouseEvent.MOUSE_DOWN,mousedown);
this.addEventListener(MouseEvent.MOUSE_UP,mouseup);
//this.addEventListener(MouseEvent.MOUSE_OUT,mousemove);
this.addChild(sp);
}
function mousemove(e:MouseEvent){
if(flag==1){
sp.graphics.lineStyle(2,0x00ff00);
sp.graphics.moveTo(x0,y0);
x0=e.localX;
y0=e.localY;
sp.graphics.lineTo(x0,y0);
}
}
function mousedown(e:MouseEvent){
flag=1;
trace(1);
}
function mouseup(e:MouseEvent){
flag=0;
trace(0);
sp.graphics..clear();
}
}
}
我想让鼠标单击moiveclip时,拖动鼠标开始画线,松开鼠标结束画线,但是总是失败,经常我已经松开鼠标了,mouse_up事件还是没有反应;经常我拖动画线的时候mouse_move断掉!请帮帮忙! 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询