AS 3.0基础(二)标跟随事件与缓冲跟随
鼠标在场景中的x与y坐标是
mouseX;
mouseY;
声明鼠标跟随事件(介绍两种给大家,其中mc_yuan是建立的一个影片剪辑,这两种非常实用)
/方法一:
Mouse.hide();
mc_yuan.addEventListener(Event.ENTER_FRAME,onmove);
function onmove(event:Event):void{
mc_yuan.x=mouseX;
mc_yuan.y=mouseY;}
方法二:
Mouse.hide();
stage.addEventListener(MouseEvent.MOUSE_MOVE,onmove);
function onmove(event:MouseEvent):void{
mc_yuan.x=mouseX;
mc_yuan.y=mouseY;}
缓冲跟随
/方法一:
mc_yuan.addEventListener(Event.ENTER_FRAME,onmove);
function onmove(event:Event):void{
mc_yuan.x=(mouseX-mc_yuan.x)/i;(i>1)
mc_yuan.y=(mouseY-mc_yuan.y)/i;(i>1)}
方法二:
stage.addEventListener(MouseEvent.MOUSE_MOVE,onmove);
function onmove(event:MouseEvent):void{
mc_yuan.x=(mouseX-mc_yuan.x)/i;(i>1);
mc_yuan.y=(mouseY-mc_yuan.y)/i;(i>1)}