大众计算机学习网

专门提供各种电脑教程

Flash _ymouse

Admin | 2012-3-13 10:28:21 | 被阅次数 | 4181

  下面的示例显示舞台的 y_mouse 位置,以及一个放在舞台上的名为 my_btn 的按钮。在时间轴的第 1 帧中输入下面的 ActionScript:

  this.createTextField("mouse_txt", 999, 5, 5, 150, 40);
  mouse_txt.html = true;
  mouse_txt.wordWrap = true;
  mouse_txt.border = true;
  mouse_txt.autoSize = true;
  mouse_txt.selectable = false;
  //
  var mouseListener:Object = new Object();
  mouseListener.onMouseMove = function() {
      var table_str:String = "<textformat tabstops='[50,100]'>";
      table_str += "<b>Stage</b>\t"+"x:"+_xmouse+"\t"+"y:"+_ymouse+newline;
      table_str += "<b>Button</b>\t"+"x:"+my_btn._xmouse+"\t"+"y:"+my_btn._ymouse+newline;
      table_str += "</textformat>";
      mouse_txt.htmlText = table_str;
  };
  Mouse.addListener(mouseListener);

  以下示例返回舞台 (_level0) 上鼠标的当前 x 和 y 坐标以及相对于舞台上名为 my_mc 的影片剪辑的坐标。

  this.createTextField("mouse_txt", this.getNextHighestDepth(), 0, 0, 150, 66);
  mouse_txt.html = true;
  mouse_txt.multiline = true;
  var row1_str:String = "&nbsp;\t<b>_xmouse\t</b><b>_ymouse</b>";
  my_mc.onMouseMove = function() {
      mouse_txt.htmlText = "<textformat tabStops='[50,100]'>";
      mouse_txt.htmlText += row1_str;
      mouse_txt.htmlText += "<b>_level0</b>\t"+_xmouse+"\t"+_ymouse;
      mouse_txt.htmlText += "<b>my_mc</b>\t"+this._xmouse+"\t"+this._ymouse;
      mouse_txt.htmlText += "</textformat>";
  };