![]() |
![]() |
||||||
|
|||||||
| Tags: |
![]() |
|
|||
|
The code below is pretty straightforward, but it slows down remarkably quickly.
Why does this happen and is there anything I could do to speed it up? Thanks! <?xml version="1.0"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()"> <mx:UIComponent id="mainDisplay"/> <mx:Script> <![CDATA[ import flash.display.Shape; import flash.events.TimerEvent; import flash.utils.Timer; private var shape1:Shape private function init():void { var myTimer:Timer = new Timer(1); var timeInterval:int=0 myTimer.addEventListener("timer", timerHandler); myTimer.start(); var x:int function timerHandler():void{ x++ timeInterval+=1 drawWedge(100,300, timeInterval, 360, 100, 100) trace(x) } } private function drawWedge(x, y, startAngle, arc, radius, yRadius):void { var segAngle:Number var theta:Number var angle:Number var angleMid:Number var segs:Number var ax:Number var ay:Number var bx:Number var by:Number var cx:Number var cy:Number // Flash uses 8 segments per circle, to match that, we draw in a maximum // of 45 degree segments. First we calculate how many segments are needed // for our arc. segs = Math.ceil(Math.abs(arc)/45); // Now calculate the sweep of each segment. segAngle = arc/segs; // The math requires radians rather than degrees. To convert from degrees // use the formula (degrees/180)*Math.PI to get radians. theta = -(segAngle/180)*Math.PI; // convert angle startAngle to radians angle = -(startAngle/180)*Math.PI; // draw the curve in segments no larger than 45 degrees. if (segs>0) { // draw a line from the center to the start of the curve ax = x+Math.cos(startAngle/180*Math.PI)*radius; ay = y+Math.sin(-startAngle/180*Math.PI)*yRadius; shape1=new Shape shape1.graphics.moveTo(x, y); shape1.graphics.lineStyle(1, 0xFFff00); shape1.graphics.lineTo(ax, ay); // Loop for drawing curve segments for (var i:int = 0; i<segs; i++) { angle += theta; angleMid = angle-(theta/2); bx = x+Math.cos(angle)*radius; by = y+Math.sin(angle)*yRadius; cx = x+Math.cos(angleMid)*(radius/Math.cos(theta/2)); cy = y+Math.sin(angleMid)*(yRadius/Math.cos(theta/2)); shape1.graphics.curveTo(cx, cy, bx, by); } mainDisplay.addChild(shape1) // close the wedge by drawing a line to the center //shape1.graphics.beginFill(0xFF0000); shape1.graphics.lineTo(x, y); //shape1.graphics.endFill(); } }; ]]> </mx:Script> </mx:Application> |
| Sponsored Links |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
- Contact Us
-|-
Adobe Dreamweaver Forums -|-
Archive -|-
Top -|-Rules/Disclaimer-|-Help/Support-|-Advertise