做的一个点子地图里测距的功能 如下代码
on (release) {
measure ();
function measure (){
this.createEmptyMovieClip("canvas_mc", this.getNextHighestDepth());
var mouseListener:Object = new Object();
mouseListener.onMouseDown = function() {
this.isDrawing = true;
this.orig_x = _xmouse;
this.orig_y = _ymouse;
this.target_mc = canvas_mc.createEmptyMovieClip("", canvas_mc.getNextHighestDepth());
}
mouseListener.onMouseMove = function() {
if (this.isDrawing) {
this.target_mc.clear();
this.target_mc.lineStyle(1, 0xFF0000, 100);
this.target_mc.moveTo(this.orig_x, this.orig_y);
this.target_mc.lineTo(_xmouse, _ymouse);
}
updateAfterEvent();
mouseListener.onMouseUp = function() {
line_width=_xmouse-this.orig_x;
line_height=_ymouse-this.orig_y;
this.isDrawing = false;
var l:Number = Math.sqrt(Math.pow(line_width, 2)+Math.pow(line_height, 2))*2500/map_mc._xscale;
line_mc.createTextField("length"+nextDepth+"_txt",canvas_mc.getNextHighestDepth(),(this.orig_x+_xmouse)/2-10, this.orig_y+_ymouse)/2-20, 1, 1);
line_mc['length'+nextDepth+'_txt'].text = Math.round(l);
}
Mouse.addListener(mouseListener);
}
有两行老是有错误
var l:Number = Math.sqrt(Math.pow(line_width, 2)+Math.pow(line_height, 2))*2500/map_mc._xscale;
line_mc.createTextField("length"+nextDepth+"_txt",canvas_mc.getNextHighestDepth(),(this.orig_x+_xmouse)/2-10, this.orig_y+_ymouse)/2-20, 1, 1);
求指点
on (release) {
measure ();
function measure (){
this.createEmptyMovieClip("canvas_mc", this.getNextHighestDepth());
var mouseListener:Object = new Object();
mouseListener.onMouseDown = function() {
this.isDrawing = true;
this.orig_x = _xmouse;
this.orig_y = _ymouse;
this.target_mc = canvas_mc.createEmptyMovieClip("", canvas_mc.getNextHighestDepth());
}
mouseListener.onMouseMove = function() {
if (this.isDrawing) {
this.target_mc.clear();
this.target_mc.lineStyle(1, 0xFF0000, 100);
this.target_mc.moveTo(this.orig_x, this.orig_y);
this.target_mc.lineTo(_xmouse, _ymouse);
}
updateAfterEvent();
mouseListener.onMouseUp = function() {
line_width=_xmouse-this.orig_x;
line_height=_ymouse-this.orig_y;
this.isDrawing = false;
var l:Number = Math.sqrt(Math.pow(line_width, 2)+Math.pow(line_height, 2))*2500/map_mc._xscale;
line_mc.createTextField("length"+nextDepth+"_txt",canvas_mc.getNextHighestDepth(),(this.orig_x+_xmouse)/2-10, this.orig_y+_ymouse)/2-20, 1, 1);
line_mc['length'+nextDepth+'_txt'].text = Math.round(l);
}
Mouse.addListener(mouseListener);
}
有两行老是有错误
var l:Number = Math.sqrt(Math.pow(line_width, 2)+Math.pow(line_height, 2))*2500/map_mc._xscale;
line_mc.createTextField("length"+nextDepth+"_txt",canvas_mc.getNextHighestDepth(),(this.orig_x+_xmouse)/2-10, this.orig_y+_ymouse)/2-20, 1, 1);
求指点