最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
flash as3计算二点之间的距离
时间:2022-07-02 17:02:54 编辑:袖梨 来源:一聚教程网
[代码]
//画两小圆
var yuan1:Sprite=new Sprite();
yuan1.graphics.beginFill(0x000000);
yuan1.graphics.drawCircle(0,0,5);
addChild(yuan1);
yuan1.x=100;
yuan1.y=100;
var yuan2:Sprite=new Sprite();
yuan2.graphics.beginFill(0x000000);
yuan2.graphics.drawCircle(0,0,5);
addChild(yuan2);
yuan2.x=130;
yuan2.y=140;
//显赫距离的动态文本
var _txt:TextField=new TextField();
_txt.autoSize=TextFieldAutoSize.LEFT;
addChild(_txt);
//定义直线精灵
var zhixian:Sprite=new Sprite();
addChild(zhixian);
//圆1拖动和停止拖动
yuan1.buttonMode=true;
yuan1.addEventListener(MouseEvent.MOUSE_DOWN,yuan1ax);
function yuan1ax(event:MouseEvent):void {
yuan1.startDrag();
}
yuan1.addEventListener(MouseEvent.MOUSE_MOVE,yuan1yd);
function yuan1yd(event:MouseEvent):void {
event:gx;
}
yuan1.addEventListener(MouseEvent.MOUSE_UP,yuan1sk);
function yuan1sk(event:MouseEvent):void {
yuan1.stopDrag();
}
stage.addEventListener(MouseEvent.MOUSE_UP,yuan1yc);
function yuan1yc(event:MouseEvent):void {
yuan1.stopDrag();
}
//圆2拖动和停止拖动
yuan2.buttonMode=true;
yuan2.addEventListener(MouseEvent.MOUSE_DOWN,yuan2ax);
function yuan2ax(event:MouseEvent):void {
yuan2.startDrag();
}
yuan2.addEventListener(MouseEvent.MOUSE_MOVE,yuan2yd);
function yuan2yd(event:MouseEvent):void {
event:gx;
}
yuan2.addEventListener(MouseEvent.MOUSE_UP,yuan2sk);
function yuan2sk(event:MouseEvent):void {
yuan2.stopDrag();
}
stage.addEventListener(MouseEvent.MOUSE_UP,yuan2yc);
function yuan2yc(event:MouseEvent):void {
yuan2.stopDrag();
}
//更新
stage.addEventListener(Event.ENTER_FRAME,gx);
function gx(event:Event):void {
zhixian.graphics.clear();
var zuobiao1oint = new Point(yuan1.x, yuan1.y);
var zuobiao2oint = new Point(yuan2.x, yuan2.y);
var juli:Number = Point.distance(zuobiao1, zuobiao2);
zhixian.graphics.lineStyle(2,0xFF0000,1);
zhixian.graphics.moveTo(yuan1.x,yuan1.y);
zhixian.graphics.lineTo(yuan2.x,yuan2.y);
_txt.text="两点间距离:"+uint(juli*10)/10;
}
相关文章
- 人们熟悉的寄居蟹属于以下哪种分类 神奇海洋11月21日答案 11-21
- 第五人格11.22共研服有什么更新 11月22日共研服更新内容介绍 11-21
- 原神恰斯卡怎么培养 11-21
- 无期迷途四星装束是谁 11-21
- 王者荣耀帝丹高中校服怎么获得 11-21
- 光遇姆明季后续版本怎么玩 11-21