Flash中的_xmouse
2012-06-02 19:59:28 来源:开发学院下面的示例显示舞台的 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);
- ››FLASH不等于运算符!=的使用实例
- ››FLASH不全等运算符!==
- ››FLASH字符串分隔符运算符
- ››FLASH% 模运算符
- ››Flash+、++、+= 加法运算符
- ››Flash, 逗号运算符
- ››flash中的-、--、-=减法运算符
- ››Flash的-Infinity 常数、.点运算符、/ 除法运算符...
- ››Flash两种注释方法/*..*/ 和// 注释行分隔符运算符...
- ››Flash的/=除法赋值运算符、=赋值运算符、== 等于运...
- ››Flash之?: 条件运算符、^ 按位 XOR 运算符、^= 按...
- ››Flash的_framesloaded代码示例
更多精彩
赞助商链接