WEB开发网
开发学院图形图像Flash Flash中的_xmouse 阅读

Flash中的_xmouse

 2012-06-02 19:59:28 来源:开发学院   
核心提示:下面的示例显示舞台的 xmouse 位置,以及一个放在舞台上的名为 my_btn 的按钮,Flash中的_xmouse,在时间轴的第 1 帧中输入下面的 ActionScript: this.createTextField("mouse_txt", 999, 5, 5, 150, 40);mouse

下面的示例显示舞台的 xmouse 位置,以及一个放在舞台上的名为 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 = " \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>";
  };

下面的示例在舞台上创建三个文本字段。mouse_txt 实例显示鼠标相对于舞台的当前位置。textfield_txt 实例显示鼠标指针相对于 my_txt 实例的当前位置。请将以下 ActionScript 添加到 FLA 或 AS 文件:

this.createTextField("mouse_txt", this.getNextHighestDepth(), 10, 10, 200, 22);
  mouse_txt.border = true;
  this.createTextField("textfield_txt", this.getNextHighestDepth(), 220, 10, 200, 22);
  textfield_txt.border = true;
  this.createTextField("my_txt", this.getNextHighestDepth(), 100, 100, 160, 120);
  my_txt.border = true;

var mouseListener:Object = new Object();
  mouseListener.onMouseMove = function() {
     mouse_txt.text = "MOUSE ... X:" + Math.round(_xmouse) + ",\tY:" + Math.round(_ymouse);
     textfield_txt.text = "TEXTFIELD ... X:" + Math.round(my_txt._xmouse) + ",\tY:" +
     Math.round(my_txt._ymouse);
  }

Mouse.addListener(mouseListener);

Tags:Flash xmouse

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接