zoukankan      html  css  js  c++  java
  • 关于设计:Actionscript 有关鼠标事件笔记

    1、鼠标手指状指针的使用设置,将鼠标指针变换为手指状。

     1 boy_mc.buttonMode = true;
     2 boy_mc.addEventListener("mouseOver", overMc);
     3 function overMc(me:MouseEvent){
     4  boy_mc.useHandCursor = false;
     5 }
     6 boy_mc.addEventListener("mouseDown", downMc);
     7 function downMc(me:MouseEvent){
     8  boy_mc.useHandCursor = true;
     9  boy_mc.startDrag();
    10  boy_mc.alpha = 0.8;
    11 }
    12 boy_mc.addEventListener("mouseUp", upMc);
    13 function upMc(me:MouseEvent){
    14  boy_mc.useHandCursor = false;
    15  boy_mc.stopDrag();
    16  boy_mc.alpha = 1;
    17 }

    2、自定义鼠标指针。

    1 Mouse.hide();
    2 hand_mc.startDrag(true);

    3、自动回旋的追踪鼠标指针效果。利用指针位置与相关三角函数方法sin()、cos()、atan2()来旋转移动影片剪辑。

     1 var speed=10;
     2 var disX,disY,radi;
     3 function mousRot(){
     4  radi=Math.atan2(disY,disX);
     5  var de=angle(radi);
     6  mouse_mc.rotation=de;
     7 }
     8 function angle(radi){
     9  var de=radi * 180 /Math.PI;
    10  return(de);
    11 }
    12 this.addEventListener(Event.ENTER_FRAME,traceMous);
    13 function traceMous(me:Event){
    14  disX=this.mouseX-mouse_mc.x;
    15  disY=this.mouseY-mouse_mc.y;
    16  var dis=Math.sqrt(disX * disX + disY * disY);
    17  if (dis>speed){
    18   mousRot();
    19   var spX=Math.cos(radi) * speed;
    20   var spY=Math.sin(radi) * speed;
    21   mouse_mc.x += spX;
    22   mouse_mc.y += spY;
    23  }else if (mouse_mc.x != this.mouseX && mouse_mc.y != this.mouseY){
    24   mousRot();
    25   mouse_mc.x=this.mouseX;
    26   mouse_mc.y=this.mouseY;
    27  }
    28 }

    4、随鼠标指针飘荡的文字

     1 var wordArr=[word1_mc,word2_mc,word3_mc,word4_mc,word5_mc,word6_mc,word7_mc,word8_mc,word9_mc,word10_mc,word11_mc,word12_mc,word13_mc];
     2 var arrLen=wordArr.length-1;
     3 this.addEventListener(Event.ENTER_FRAME,moveWord);
     4 function moveWord(me:Event)
     5 {
     6  wordArr[0].x=stage.mouseX + 12;
     7  wordArr[0].y=stage.mouseY + 12;
     8  var i=0;
     9  do  {
    10   wordArr[i+1].x += (wordArr[i].x - wordArr[i+1].x)/2 + 12;
    11   wordArr[i+1].y += (wordArr[i].y - wordArr[i+1].y)/2;
    12   i++;
    13  }while(i<arrLen)
    14 }

    5、随鼠标指针缩放的幽灵群。在元件中建立2个关键帧

    1 var dx=stage.mouseX - this.x;
    2 var dy=stage.mouseY - this.y;
    3 var size = 115 - (Math.sqrt(dx * dx + dy * dy) / 3);
    4 if (size<0){
    5  size=0;
    6 }
    7 this.alpha =  size / 70;
    8 this.width = size;
    9 this.height = size;
    1 this.gotoAndPlay(1);

    6、产生鼠标移动轨迹的效果。

    场景中

    1 stage.addEventListener(MouseEvent.MOUSE_MOVE,traceobj);
    2 function traceobj(me:MouseEvent){
    3  var copy_mc:bubbleA=new bubbleA();
    4   copy_mc.x=stage.mouseX;
    5   copy_mc.y=stage.mouseY;
    6   this.addChild(copy_mc);
    7 }

    元件中最后一帧

    1 this.parent.removeChild(this);
    2 stop();

    7、随鼠标移动的射击游戏瞄准器。

    1 stage.addEventListener("mouseMove",moveTarget);
    2 function moveTarget(me:MouseEvent){
    3  hLine_mc.y=mouseY;
    4  vLine_mc.x=mouseX;
    5  scope_mc.y=mouseY;
    6  scope_mc.x=mouseX;
    7  me.updateAfterEvent();
    8 }

    8、随鼠标指针移动的目光。

    眼睛元件上的AS代码

    1 stage.addEventListener(Event.ENTER_FRAME,moveEye);
    2 function moveEye(me:Event){
    3  var dx=stage.mouseX-this.x;
    4  var dy=stage.mouseY-this.y;
    5  var rad=Math.atan2(dy,dx);
    6  var deg=180 * rad / Math.PI;
    7  this.rotation=deg;
    8 }
  • 相关阅读:
    神奇的python系列10:函数(三)
    神奇的python系列9:函数(二)
    神奇的python系列8:函数(一)
    神奇的python系列7:文件操作
    神奇的python系列6:python基础数据类型补充
    神奇的python系列5:python基础数据类型三(字典)
    神奇的python系列4:python基础数据类型二(列表)
    神奇的python系列3:python基础数据类型一
    神奇的python系列2:python基础一
    Token机制,session机制
  • 原文地址:https://www.cnblogs.com/cnsg/p/as3.html
Copyright © 2011-2022 走看看