链条处理
Posted jiangjieqm
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了链条处理相关的知识,希望对你有一定的参考价值。
package framework.utilt { import flash.display.DisplayObject; import flash.geom.Point; import flash.net.LocalConnection; import flash.system.System; public class Utilts { /** * AS3冒泡排序算法 * @param arr 需要排序的数组 * @param isAsc 是否升序 * @return 返回排序后的数组 */ public static function BubbleSort(arr:Array, isAsc:Boolean = true):Array { if(arr == null) { throw new Error("Array is null."); } var tmp:*; if(isAsc) { for(var i:int = 0; i < arr.length; i++) { for(var j:int = i; j < arr.length; j++) { if(arr[i] > arr[j]) { tmp = arr[i]; arr[i] = arr[j]; arr[j] = tmp; } } } } else { for(i = 0; i < arr.length; i++) { for(j = i; j < arr.length; j++) { if(arr[i] < arr[j]) { tmp = arr[i]; arr[i] = arr[j]; arr[j] = tmp; } } } } return arr; } /** *flash gc */ public static function GC():void{ trace(System.totalMemory/1024,"gc"); try { new LocalConnection().connect(‘foo‘); new LocalConnection().connect(‘foo‘); } catch (e:*) {} // 强制执行垃圾回收进程。 // 仅限于 Flash Player 调试版和 AIR 应用程序。在 AIR 应用程序中,System.gc() 方法仅限在运行于 // AIR Debug Launcher (ADL) 中的内容或已安装的应用程序的应用程序安全沙箱中的内容中启用。 //System.gc();//Debug版本有效 } private static function getRotation(p1:Point,p2:Point):Number { var r:Number=Math.PI/2; if(p1.x!=p2.x) { r=Math.atan((p1.y-p2.y)/(p1.x-p2.x)); } return r; } private static function radianToAngle(radian:Number):Number { return radian*(180/Math.PI); } /** * @param _st * @param _end * @return */ public static function GetRotation(_st:Point,_end:Point):Number { var angle:Number = getRotation(_st,_end); var last:Number = radianToAngle(angle); if(_end.x - _st.x < 0) { last -= 180; } return last; } /** *生成角度,长度 * @param list * @return * */ public static function GetLink(list:Array):Array { if(!list || list.length < 2) { throw new Error("LinkMC error!"); } var res:Array = []; var len:int = list.length; for(var i:int = 0;i < len - 1;i++) { var s:Point = list[i]; var e:Point = list[i+1]; var angle:Number = GetRotation(s,e); var dis:Number = Point.distance(s,e); var o:Object = new Object(); o.ang = angle; o.d = dis; o.x = s.x; o.y = s.y; res[i] = o; } return res; } } }
package { import flash.display.Bitmap; import flash.display.DisplayObject; import flash.display.Graphics; import flash.display.MovieClip; import flash.display.Sprite; import flash.events.MouseEvent; import flash.geom.Point; import flash.utils.getDefinitionByName; import framework.baseUI.JButton; import framework.ini.SignIni; import framework.loader.ElementLoader; import framework.utilt.Utilts; public class Test0 extends Sprite { // private var bmp:Bitmap; private var _bg:Sprite; private var list:Array; private var _class:Class; public function Test0() { list=[]; var btn:JButton = new JButton(onBtnMouseEvt,"build","build",true); addChild(btn); var clearbtn:JButton = new JButton(onBtnMouseEvt,"clear","clear",true); clearbtn.y = 50; addChild(clearbtn); // graphics.beginFill(0xff0000,0.1); // graphics.drawRect(0,0,800,600); // graphics.endFill(); _bg = new Sprite(); _bg.x = 100; _bg.graphics.beginFill(0xff0000,0.1); _bg.graphics.drawRect(0,0,800,600); _bg.graphics.endFill(); _bg.addEventListener(MouseEvent.CLICK,onMouseEvt); addChild(_bg); ElementLoader.instance.load("0.swf",SignIni.TYPE_SWF,onComplete); } private function onBtnMouseEvt(e:MouseEvent):void { if((e.target as JButton).name == "build") { var arr:Array = Utilts.GetLink(list); for(var i:int = 0;i < arr.length;i++) { var o:Object = arr[i]; addArrow(o.ang,o.d,o.x,o.y); } } else { } } private function addArrow(ang:Number,dis:Number,x:Number,y:Number):void { // var mc:MovieClip = new _class() as MovieClip; var mc:Sprite = new Sprite(); mc.graphics.beginFill(0xffff00,0.5); mc.graphics.drawRect(0,0,dis,20); mc.mouseEnabled = false; mc.rotation = ang; // mc.width = dis; mc.x = x; mc.y = y; _bg.addChild(mc); } private function onMouseEvt(e:MouseEvent):void { // trace(e.localX ); var _x:Number = e.localX var _y:Number = e.localY; var g:Graphics = _bg.graphics; g.beginFill(0xff0000); g.drawCircle(_x,_y,2); g.endFill(); list.push(new Point(_x,_y)); } private function onComplete(dis:DisplayObject):void { // bmp = dis as Bitmap; // addChild(bmp); var c:Class = getDefinitionByName("com.arrow") as Class; // var mc:MovieClip = new c() as MovieClip; // mc.mouseEnabled = false; // mc.width = 600; // addChild(mc); _class = c; } } } import flash.display.Shape; class Cir extends Shape { public function Cir() { graphics.beginFill(0xff0000); graphics.drawCircle(0,0,5); graphics.endFill(); } }
以上是关于链条处理的主要内容,如果未能解决你的问题,请参考以下文章