{"id":679,"date":"2007-06-15T20:38:14","date_gmt":"2007-06-16T01:38:14","guid":{"rendered":"http:\/\/www.lonhosford.com\/lonblog\/?p=679"},"modified":"2015-07-31T18:25:52","modified_gmt":"2015-07-31T23:25:52","slug":"actionscript-3-revolving-animation-around-a-center-point","status":"publish","type":"post","link":"https:\/\/www.lonhosford.com\/lonblog\/2007\/06\/15\/actionscript-3-revolving-animation-around-a-center-point\/","title":{"rendered":"Actionscript 3 Revolving Animation Around a Center Point"},"content":{"rendered":"<p><strong>By Lon (Alonzo) Hosford<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" src=\"http:\/\/lh5.ggpht.com\/_e5pwU0LJbN8\/TG09LlXZxII\/AAAAAAAAFrE\/LPpTBdotmBI\/s144\/Animation_Circular_Rotation_A8-19-2010%2010-17-02%20AM.png\" class=\"alignleft\" width=\"144\" height=\"120\" \/>I was working through chapter 3 of Keith Peter&#8217;s <a href=\"http:\/\/www.amazon.com\/gp\/product\/1590597915?ie=UTF8&amp;tag=hosfordusa&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=1590597915\">Foundation Actionscript 3.0 Animation: Making Things Move<\/a> and came up with this <code>Rotator<\/code> class that will revolve any sprite around a given point. <\/p>\n<figure style=\"width: 134px\" class=\"wp-caption alignright\"><a href=\"http:\/\/www.amazon.com\/gp\/product\/1590597915?ie=UTF8&amp;tag=hosfordusa&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=1590597915\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\"  src=\"http:\/\/lh4.ggpht.com\/_e5pwU0LJbN8\/TF1xrKyqv4I\/AAAAAAAAFqI\/IFBuU9b7ijs\/s800\/51PvDwNRxYL._SL160_.jpg\" alt=\"Keith Peters AS3 Animation\" width=\"134\" height=\"160\" class=\"  \" title=\"Keith Peters AS3 Animation\"\/><\/a><figcaption class=\"wp-caption-text\">Learn More<\/figcaption><\/figure>\n<p>[August 18 2010] I updated this to an ActionScript project to Flex Builder 4. <a href=\"https:\/\/www.lonhosford.com\/content\/flex\/animation\/Animation_Circular_Rotation.zip\">Download the example code<\/a>. You can build this with the free Flex SDK by using the code in the src folder. Same for Flash CS3 and CS4. You need to create a Flash Document in the src folder and set the document class to <code>Chapter02_Factory_PrintCenters<\/code>. For your convenience you can <a href=\"https:\/\/www.lonhosford.com\/content\/flex\/animation\/Animation_Circular_Rotation_Flash_CS4.zip\">download a Flash CS4 ready to go example<\/a>.<\/p>\n<p><strong>Application Class &#8211; Animation_Circular_Rotation<\/strong><br \/>\nThis is the application class. The actual use of the <code>Rotator<\/code> class is all done on lines 81 to 86 with the <code>_rotator<\/code> instance and the <code>Circle<\/code> class <code>circle<\/code> instance. The rest of this class is dedicated to user interaction with the keyboard to start, stop and step the animation and with informational feedback using the <code>DebugConsole<\/code> class. <\/p>\n<p>The <code>circle<\/code> created on line 80 is what the <code>Rotator<\/code> class instance <code>_rotator<\/code> revolves. The Rotator class constructor requires the <code>Sprite<\/code> object it will revolve and the radius as shown on line 85.<\/p>\n<pre class=\"brush: as3; highlight: [80,83,84,85,86]; title: ; wrap-lines: false; notranslate\" title=\"\">\r\n\/**\r\n *  Purpose: Animating a rotation motion in Actionscript 3\r\n *  &lt;p&gt;Author: Lon Hosford https:\/\/www.lonhosford.com 908 996 3773&lt;\/p&gt;\r\n *  &lt;p&gt;Version history:&lt;\/p&gt;\r\n *  &lt;p&gt;\tNumber:\t\t\t1.00.00&lt;\/p&gt;\r\n *  &lt;p&gt;\tDate:\t\t\t06\/15\/2007&lt;\/p&gt;\r\n *  &lt;p&gt;\tProgrammer:\t\tLon Hosford: https:\/\/www.lonhosford.com&lt;\/p&gt;\r\n *  &lt;p&gt;\tChanges:\t\tOriginal programming&lt;\/p&gt;\r\n * *\/\t\r\n\r\npackage\r\n{\r\n\timport com.lonhosford.util.debug.lite.DebugConsole;\r\n\t\r\n\timport flash.display.Shape;\r\n\timport flash.display.Sprite;\r\n\timport flash.display.StageScaleMode;\r\n\timport flash.events.Event;\r\n\timport flash.events.KeyboardEvent;\r\n\timport flash.events.TimerEvent;\r\n\timport flash.system.Capabilities;\r\n\timport flash.text.TextField;\r\n\timport flash.text.TextFormat;\r\n\timport flash.text.TextFormatAlign;\r\n\timport flash.ui.Keyboard;\r\n\timport flash.utils.Timer;\r\n\t\r\n\r\n\t&#x5B;SWF(width=600, height = 770, frameRate = 30)]\r\n\t\/**\r\n\t *  Application class\r\n\t * *\/\t\r\n\tpublic class Animation_Circular_Rotation extends Sprite\r\n\t{\r\n\t\tprivate var _debugConsole:DebugConsole = DebugConsole.getInstance();\r\n\t\tpublic var maxDebugConsoleLines:Number = 500;\t\t\t\t\/\/ Maximum lines in debug console.\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\/\/ More line lowers performance.\r\n\t\t\/\/ Basic background - set your preference here\r\n\t\tpublic static const backgroundColor:Number = 0xcccccc;\r\n\t\tpublic static const backgroundBorderColor:Number = 0x666666;\r\n\t\tpublic static const backgroundBorderWidth:Number = 2;\r\n\t\t\r\n\t\tprivate var _rotator:Rotator;\t\t\t\t\t\t\t\t\/\/ Rotation animator\r\n\t\t\r\n\t\t\/\/ Language\r\n\t\tprivate var _lang_clickStage:String = &quot;Click stage to get keyboard focus.&quot;;\r\n\t\tprivate var _lang_enterKey:String = &quot;ENTER starts and stops animation.&quot;;\r\n\t\tprivate var _lang_spacebar:String = &quot;SPACE BAR increments animation one step. Auto repeats after delay.&quot;;\r\n\t\tprivate var _lang_debugCleared:String = &quot;Debug window cleared every&quot;;\r\n\t\tprivate var _lang_debugClearedWhen:String = &quot;lines when animating to maintain low memory.&quot;;\r\n\t\tprivate var _lang_traceDisabled:String = &quot;Trace output suppressed when animation plays in Flash Control-&gt;Test Movie.&quot;;\r\n\t\tprivate var _lang_keyboardShortcuts:String = &quot;In Flash after Control-&gt;Test Movie, select Control-&gt;Disable Keyboard Shortcuts.&quot;;\r\n\t\t\/\/ Space bar repeat timer\r\n\t\tprivate var _keySpacebarTimeDelay:Number = 350;\t\t\t\t\t\/\/ Delay between each Keyboard.SPACE event.\r\n\t\tprivate var _keySpacebarTimer:Timer; \t\t\t\t\t\t\t\/\/ Timer for repeating Keyboard.SPACE events.\r\n\r\n\t\tpublic function Animation_Circular_Rotation()\r\n\t\t{\r\n\t\t\t\/\/ Set stage options\r\n\t\t\tinitStage();\r\n\t\t\t\/\/ Create a background\r\n\t\t\tvar backgroundRect:Shape = getRectShape(backgroundColor, backgroundBorderColor, backgroundBorderWidth, stage.stageWidth, stage.stageHeight)\r\n\t\t\taddChild(backgroundRect);\r\n\t\t\t\r\n\t\t\t\/\/ Add output monitor\r\n\t\t\tstage.addChild(_debugConsole);\r\n\t\t\t_debugConsole.width = stage.stageWidth;\r\n\t\t\t_debugConsole.height = stage.stageHeight * .25;\r\n\t\t\t_debugConsole.y = stage.stageHeight - _debugConsole.height;\r\n\t\t\t\/\/ Disable tracing to Flash External player. Tracing impairs performance.\r\n\t\t\tif ( Capabilities.playerType == &quot;External&quot;)\r\n\t\t\t{\r\n\t\t\t\t_debugConsole.isTracing = false;\r\n\t\t\t}\r\n\t\t\t\/\/ Instructions\r\n\t\t\tvar instruction_tf:TextField = instructionDisplay();\r\n\t\t\taddChild(instruction_tf);\r\n\t\t\tinstruction_tf.x = (stage.stageWidth - instruction_tf.width) \/ 2;\r\n\t\t\t\r\n\t\t\t\/\/ Create sprite to rotate\r\n\t\t\tvar circle:Circle = new Circle();\r\n\t\t\t\r\n\t\t\t\/\/ Create a rotator\r\n\t\t\t_rotator = new Rotator(circle, backgroundRect.width * .3);\r\n\t\t\t_rotator.x = (stage.stageWidth - _rotator.width) \/ 2;\r\n\t\t\t_rotator.y = instruction_tf.y + instruction_tf.height + 5;\r\n\t\t\taddChild(_rotator);\r\n\t\t\t_rotator.addEventListener(Event.ENTER_FRAME,rotatorEnterFrameEventHandler);\r\n\t\t\t\r\n\t\t\t\/\/ Use keyboard events to control the animation\r\n\t\t\tstage.addEventListener( KeyboardEvent.KEY_DOWN, keyPressed);\r\n\t\t\tstage.addEventListener( KeyboardEvent.KEY_UP, keyReleased);\r\n\t\t\t\r\n\t\t\t_keySpacebarTimer = new Timer(_keySpacebarTimeDelay,1); \r\n\t\t\t_keySpacebarTimer.addEventListener(TimerEvent.TIMER, keySpacebarTimerEventHandler);\r\n\t\t}\r\n<\/pre>\n<p>[ad name=&#8221;Google Adsense&#8221;]<\/p>\n<pre class=\"brush: as3; first-line: 96; title: ; wrap-lines: false; notranslate\" title=\"\">\r\n\r\n\t\t\/**\r\n\t\t * Set any stage options per your needs\r\n\t\t * *\/\r\n\t\tprivate function initStage():void \r\n\t\t{ \r\n\t\t\tstage.scaleMode = StageScaleMode.NO_SCALE;\r\n\t\t}\r\n\t\t\/**\r\n\t\t * Instructions display.\r\n\t\t * *\/\r\n\t\tprivate function instructionDisplay():TextField \r\n\t\t{\r\n\t\t\tvar instructions_tf:TextField = new TextField();\t\t\r\n\t\t\tvar format:TextFormat = new TextFormat();\r\n\t\t\tformat.font = &quot;_typewriter&quot;;\r\n\t\t\tformat.color = 0x000000;\r\n\t\t\tformat.size = 12;\r\n\t\t\tformat.indent = 2;\r\n\t\t\tinstructions_tf.defaultTextFormat = format;\r\n\t\t\tinstructions_tf.border = true;\r\n\t\t\tinstructions_tf.borderColor = 0x000000;\r\n\t\t\tinstructions_tf.background = true;\r\n\t\t\tinstructions_tf.backgroundColor = 0xffffff;\r\n\t\t\tinstructions_tf.autoSize = TextFormatAlign.LEFT\r\n\t\t\tinstructions_tf.appendText(_lang_clickStage + &quot;\\n&quot;);\r\n\t\t\tinstructions_tf.appendText(_lang_enterKey + &quot;\\n&quot;);\r\n\t\t\tinstructions_tf.appendText(_lang_spacebar + &quot;\\n&quot;);\r\n\t\t\tinstructions_tf.appendText(_lang_debugCleared + &quot; &quot; + maxDebugConsoleLines + &quot; &quot; + _lang_debugClearedWhen + &quot;\\n&quot;);\r\n\t\t\tinstructions_tf.appendText(_lang_traceDisabled + &quot;\\n&quot;);\r\n\t\t\tinstructions_tf.appendText(_lang_keyboardShortcuts);\r\n\t\t\t\r\n\t\t\treturn instructions_tf;\r\n\t\t}\r\n\t\t\/**\r\n\t\t * Handler for KeyboardEvent.KEY_DOWN\r\n\t\t * *\/\r\n\t\tprivate function keyPressed(evt:KeyboardEvent):void \r\n\t\t{\r\n\t\t\t\r\n\t\t\tswitch (evt.keyCode)\r\n\t\t\t{\r\n\t\t\t\tcase Keyboard.SPACE:\r\n\t\t\t\t\t\r\n\t\t\t\t\tif (!_keySpacebarTimer.running)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_keySpacebarTimer.start();\r\n\t\t\t\t\t}\t\r\n\t\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\t\/**\r\n\t\t * Handler for KeyboardEvent.KEY_UP \r\n\t\t * *\/\r\n\t\tprivate function keyReleased(evt:KeyboardEvent):void \r\n\t\t{\r\n\t\t\tswitch (evt.keyCode)\r\n\t\t\t{\r\n\t\t\t\tcase Keyboard.SPACE:\r\n\t\t\t\t\tif (_keySpacebarTimer.running)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_keySpacebarTimer.stop();\r\n\t\t\t\t\t\t_keySpacebarTimer.reset();\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (_rotator.isPlaying)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_rotator.stop();\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_rotator.step();\r\n\t\t\t\t\t}\r\n\t\t\t\t\t\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tcase Keyboard.ENTER:\r\n\t\t\t\t\tif (_rotator.isPlaying)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_rotator.stop();\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t_rotator.start();\r\n\t\t\t\t\t}\r\n\t\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\t\/**\r\n\t\t * Handler for TimerEvent.TIMER event. Resets the delay interval once the default delay \r\n\t\t * is reached.\r\n\t\t * *\/\r\n\t\tprivate function keySpacebarTimerEventHandler(event:TimerEvent):void \r\n\t\t{\r\n\t\t\t_rotator.start();\r\n\t\t}\r\n\t\t\/**\r\n\t\t * Handler for _rotator Event.ENTER_FRAME event. \r\n\t\t * *\/\r\n\t\tprivate function rotatorEnterFrameEventHandler(event:Event):void \r\n\t\t{\r\n\t\t\tclearDebugConsoleFlashExternalPlayer();\r\n\t\t}\r\n\t\t\/**\r\n\t\t * Handles slower processing in Flash external player Control-&gt;Test Movie\r\n\t\t * and clears debugConsole when 100 lines are reached.\r\n\t\t * *\/\r\n\t\t\r\n\t\tprivate function clearDebugConsoleFlashExternalPlayer():void\r\n\t\t{\r\n\t\t\tif (_debugConsole.contentLineCount &gt; maxDebugConsoleLines &amp;&amp; _rotator.isPlaying )\r\n\t\t\t{\r\n\t\t\t\t_debugConsole.clear();\r\n\t\t\t\t\r\n\t\t\t}\r\n\t\t}\r\n\t\t\/**\r\n\t\t * Utility to draw a rectangle Shape object \r\n\t\t * *\/\r\n\t\tprivate function getRectShape(bgColor:uint, borderColor:uint, borderSize:uint, width:uint, height:uint):Shape \r\n\t\t{\r\n\t\t\tvar newShape:Shape = new Shape();\r\n\t\t\tnewShape.graphics.beginFill(bgColor);\r\n\t\t\tnewShape.graphics.lineStyle(borderSize, borderColor);\r\n\t\t\tnewShape.graphics.drawRect(0, 0, width, height);\r\n\t\t\tnewShape.graphics.endFill();\r\n\t\t\treturn newShape;\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<p><strong>Rotator Class<\/strong><br \/>\nThis is the class that does the rotation. The main work is done in the <code>move()<\/code> method  on lines 154 &#8211; 187.  Comments tell what each step accomplishes.  The lines past 187 in the <code>move()<\/code> method are for information only and can be deleted. The move() method only advances the animation one step defined by the <code>_vr<\/code>  variable on line 38. Increase the  <code>_vr<\/code>  variable will speed up the animation and decreasing slows the animation down. As an exercise you could make this a speed option via a setter method and the constructor.<\/p>\n<p>The <code>init()<\/code> method on lines 74 to 94 set the sprite to animate inside a rectangular boundary. <\/p>\n<pre class=\"brush: as3; title: ; wrap-lines: false; notranslate\" title=\"\">\r\npackage\r\n{\r\n\timport com.lonhosford.util.debug.lite.DebugConsole;\r\n\timport com.lonhosford.util.debug.lite.Debugger;\r\n\t\r\n\timport flash.display.Shape;\r\n\timport flash.display.Sprite;\r\n\timport flash.events.Event;\r\n\t\r\n\t\/**\r\n\t *  Purpose: Circular rotation of a sprite around a radius\r\n\t *  &lt;p&gt;Author: Lon Hosford www.lonhosford.com 908 996 3773&lt;\/p&gt;\r\n\t *  &lt;p&gt;Version history:&lt;\/p&gt;\r\n\t *  &lt;p&gt;\tNumber:\t\t\t1.00.00&lt;\/p&gt;\r\n\t *  &lt;p&gt;\tDate:\t\t\t06\/15\/2007&lt;\/p&gt;\r\n\t *  &lt;p&gt;\tProgrammer:\t\tLon Hosford: https:\/\/www.lonhosford.com&lt;\/p&gt;\r\n\t *  &lt;p&gt;\tChanges:\t\tOriginal programming&lt;\/p&gt;\r\n\t * *\/\t\r\n\tpublic class Rotator extends Sprite\r\n\t{\r\n\t\t\/**\r\n\t\t * A sprite object to rotate\r\n\t\t * *\/\r\n\t\tprivate var _spriteToRotate:Sprite;\r\n\t\t\/**\r\n\t\t * Current angle in radians. \r\n\t\t * *\/\r\n\t\tprivate var _angle:Number = 0;  \r\n\t\t\/**\r\n\t\t * Radius of rotation. \r\n\t\t * @default 150\r\n\t\t * *\/\r\n\t\tprivate var _radius:Number;\r\n\t\t\/**\r\n\t\t * Velocity of the angle change in radians. \r\n\t\t * @default .05\r\n\t\t * *\/\r\n\t\tprivate var _vr:Number = .03; \/\/ Radians\r\n\t\t\/**\r\n\t\t * Center of rotation for x.\r\n\t\t * *\/\r\n\t\tprivate var _centerX:Number;\r\n\t\t\/**\r\n\t\t * Center of rotation for y.\r\n\t\t * *\/\r\n\t\tprivate var _centerY:Number;\r\n\t\t\/**\r\n\t\t * Coordinate x for _spriteToRotate.\r\n\t\t * *\/\r\n\t\tprivate var _coordinateX:Number;\r\n\t\t\/**\r\n\t\t * Coordinate y for _spriteToRotate.\r\n\t\t * *\/\r\n\t\tprivate var _coordinateY:Number;\r\n\t\t\/**\r\n\t\t * Animation is playing.\r\n\t\t * *\/\r\n\t\tprivate var _isPlaying:Boolean = false;\r\n\t\tprivate var debugConsole:DebugConsole = DebugConsole.getInstance();\r\n\t\t\/**\r\n\t\t * Constructor\r\n\t\t * @param radius see _radius\r\n\t\t * *\/\r\n\t\tpublic function Rotator(spriteToRotate:Sprite, radius:uint = 150)\r\n\t\t{\r\n\t\t\t_spriteToRotate = spriteToRotate;\r\n\t\t\t_radius = radius;\r\n\t\t\t\r\n\t\t\tinit();\r\n\t\t}\r\n<\/pre>\n<p>[ad name=&#8221;Google Adsense&#8221;]<\/p>\n<pre class=\"brush: as3; first-line: 71; title: ; wrap-lines: false; notranslate\" title=\"\">\r\n\t\t\/**\r\n\t\t * Initialize the class\r\n\t\t * *\/\r\n\t\tprivate function init():void\r\n\t\t{\r\n\t\t\tvar boundaryBorderWidth:Number = 1\r\n\t\t\t\/\/ Create a boundaries object to set container height and width \r\n\t\t\tvar boundaries:Shape = new Shape();\r\n\t\t\tboundaries.graphics.beginFill(0xcccccc, 0);\r\n\t\t\tboundaries.graphics.lineStyle(boundaryBorderWidth, 0x000000, 0);\r\n\t\t\tboundaries.graphics.drawRect(0, 0, _radius * 2 + _spriteToRotate.width , _radius * 2 + _spriteToRotate.height );\r\n\t\t\tboundaries.graphics.endFill();\r\n\t\t\taddChild(boundaries);\r\n\t\t\t\r\n\t\t\t\/\/ Compute the center of container\r\n\t\t\t_centerX = (boundaries.width - boundaryBorderWidth)\/2 ;\r\n\t\t\t_centerY = (boundaries.height - boundaryBorderWidth)\/2  ;\r\n\t\t\t\r\n\t\t\t\/\/ Set starting position for sprite to rotate\r\n\t\t\t\r\n\t\t\t\/\/ Add sprite\r\n\t\t\t_spriteToRotate.alpha = .5;\r\n\t\t\taddChild(_spriteToRotate);\r\n\t\t\tmove();\r\n\t\t\t\r\n\t\t\t\/*----------------------------------------------------------------------\r\n\t\t\tStart statistical data for information only.\r\n\t\t\tCan delete for actual implementations\r\n\t\t\t----------------------------------------------------------------------*\/\t\t\r\n\t\t\tdebugConsole.write(&quot;\\n&quot;);\r\n\t\t\tdebugConsole.write(&quot;Rotator.init() - width:&quot; + width);\r\n\t\t\tdebugConsole.write(&quot;Rotator.init() - height:&quot; + height);\r\n\t\t\tdebugConsole.write(&quot;Rotator.init() - _angle:&quot; + _angle);\r\n\t\t\tdebugConsole.write(&quot;Rotator.init() - _radius:&quot; + _radius);\r\n\t\t\tdebugConsole.write(&quot;Rotator.init() - Math.cos(_angle):&quot; + Math.cos(_angle));\r\n\t\t\tdebugConsole.write(&quot;Rotator.init() - Math.sin(_angle):&quot; + Math.sin(_angle));\r\n\t\t\t\/*----------------------------------------------------------------------\r\n\t\t\tEnd statistical data for information only.\r\n\t\t\tCan delete above for actual implementations\r\n\t\t\t----------------------------------------------------------------------*\/\t\t\r\n\t\t}\r\n\t\t\/**\r\n\t\t * Handler for Event.ENTER_FRAME events\r\n\t\t * *\/\r\n\t\tprivate function onEnterFrame(event:Event):void\r\n\t\t{\r\n\t\t\tmove();\r\n\t\t}\r\n\t\t\/**\r\n\t\t * Get the playing status\r\n\t\t * *\/\r\n\t\tpublic function get isPlaying():Boolean\r\n\t\t{\r\n\t\t\treturn _isPlaying;\r\n\t\t}\r\n\t\t\/**\r\n\t\t * Starts the animation.\r\n\t\t * *\/\r\n\t\tpublic function start():void\r\n\t\t{\r\n\t\t\t_isPlaying = true;\r\n\t\t\taddEventListener(Event.ENTER_FRAME, onEnterFrame);\r\n\t\t}\r\n\t\t\/**\r\n\t\t * Stops the animation.\r\n\t\t * *\/\r\n\t\tpublic function stop():void\r\n\t\t{\r\n\t\t\t_isPlaying = false;\r\n\t\t\tremoveEventListener(Event.ENTER_FRAME, onEnterFrame);\r\n\t\t}\r\n\t\t\/**\r\n\t\t * Animates one unit of velocity.\r\n\t\t * *\/\r\n\t\tpublic function step():void\r\n\t\t{\r\n\t\t\tstop();\r\n\t\t\tmove();\r\n\t\t}\r\n<\/pre>\n<p>[ad name=&#8221;Google Adsense&#8221;]<\/p>\n<pre class=\"brush: as3; first-line: 150; title: ; wrap-lines: false; notranslate\" title=\"\">\r\n\t\t\/**\r\n\t\t * Animates one velocity unit.\r\n\t\t * &lt;p&gt;Performs computations for rotation and moves sprite object&lt;\/p&gt;\r\n\t\t * *\/\r\n\t\tprivate function move():void\r\n\t\t{\r\n\t\t\t\/*----------------------------------------------------------------------\r\n\t\t\tSprite coordinates\r\n\t\t\t----------------------------------------------------------------------*\/\t\t\r\n\t\t\tvar _coordinateX:Number = _centerX + Math.cos(_angle) * _radius;\r\n\t\t\tvar _coordinateY:Number = _centerY + Math.sin(_angle) * _radius;\r\n\t\t\t\/*----------------------------------------------------------------------\r\n\t\t\tPosition sprite object\r\n\t\t\t----------------------------------------------------------------------*\/\t\r\n\t\t\t_spriteToRotate.x = _coordinateX;\r\n\t\t\t_spriteToRotate.y = _coordinateY;\r\n\t\t\t\/*----------------------------------------------------------------------\r\n\t\t\tAugment the angle by the velocity\r\n\t\t\t----------------------------------------------------------------------*\/\t\t\r\n\t\t\t_angle += _vr;\r\n\t\t\t\/*----------------------------------------------------------------------\r\n\t\t\tDraw triangle\r\n\t\t\t----------------------------------------------------------------------*\/\t\t\r\n\t\t\tgraphics.clear();\r\n\t\t\tgraphics.lineStyle(1);\r\n\t\t\t\/*----------------------------------------------------------------------\r\n\t\t\tDraw hypotenuse\r\n\t\t\t----------------------------------------------------------------------*\/\t\t\r\n\t\t\tgraphics.moveTo( _coordinateX, _coordinateY );\r\n\t\t\tgraphics.lineTo(_centerX, _centerY);\r\n\t\t\t\/*----------------------------------------------------------------------\r\n\t\t\tDraw adjacent leg\r\n\t\t\t----------------------------------------------------------------------*\/\t\t\r\n\t\t\tgraphics.lineTo(_coordinateX , _centerY);\r\n\t\t\t\/*----------------------------------------------------------------------\r\n\t\t\tDraw opposite leg\r\n\t\t\t----------------------------------------------------------------------*\/\t\t\r\n\t\t\tgraphics.lineTo(_coordinateX, _coordinateY);\r\n\t\t\t\r\n\t\t\t\/*----------------------------------------------------------------------\r\n\t\t\tStart statistical data for information only.\r\n\t\t\tCan delete for actual implementations.\r\n\t\t\tdx and dy are not used in the class.\r\n\t\t\t----------------------------------------------------------------------*\/\t\t\r\n\t\t\tdebugConsole.write(&quot;\\n&quot;);\r\n\t\t\tdebugConsole.write(&quot;Rotator.move() - _vr:&quot; + _vr);\r\n\t\t\tdebugConsole.write(&quot;Rotator.move() - _angle:&quot; + _angle);\r\n\t\t\tdebugConsole.write(&quot;Rotator.move() - _coordinateX:&quot; + _coordinateX);\r\n\t\t\tdebugConsole.write(&quot;Rotator.move() - _coordinateY:&quot; + _coordinateY);\r\n\t\t\tdebugConsole.write(&quot;Rotator.move() - _centerX:&quot; + _centerX);\r\n\t\t\tdebugConsole.write(&quot;Rotator.move() - _centerY:&quot; + _centerY);\r\n\t\t\tvar dx:Number = _centerX - _coordinateX;\r\n\t\t\tvar dy:Number = _centerY - _coordinateY;\r\n\t\t\tdebugConsole.write(&quot;Rotator.move() - Length: hypotenuse:&quot; + ( Math.sqrt(dx * dx + dy * dy)  ));\r\n\t\t\tdx = _centerX - _coordinateX;\r\n\t\t\tdy = 0;\r\n\t\t\tdebugConsole.write(&quot;Rotator.move() - Length: adjacent leg:&quot; + ( Math.sqrt(dx * dx + dy * dy)  ));\r\n\t\t\tdx = 0;\r\n\t\t\tdy = _centerY - _coordinateY;\r\n\t\t\tdebugConsole.write(&quot;Rotator.move() - Length: adjacent leg:&quot; + ( Math.sqrt(dx * dx + dy * dy)  ));\r\n\t\t\r\n\t\t\t\/*----------------------------------------------------------------------\r\n\t\t\tEnd statistical data for information only.\r\n\t\t\tCan delete above for actual implementations\r\n\t\t\t----------------------------------------------------------------------*\/\t\t\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<p><strong>Circle Class<\/strong><br \/>\nThis is the sprite that is revolving in the animation.<\/p>\n<pre class=\"brush: as3; title: ; wrap-lines: false; notranslate\" title=\"\">\r\npackage {\r\n\timport flash.display.Sprite;\r\n\t\/**\r\n\t *  Purpose: Draw a circle in a Sprite\r\n\t *  &lt;p&gt;Author: Lon Hosford www.lonhosford.com 908 996 3773&lt;\/p&gt;\r\n\t *  &lt;p&gt;Version history:&lt;\/p&gt;\r\n\t *  &lt;p&gt;\tNumber:\t\t\t1.00.00&lt;\/p&gt;\r\n\t *  &lt;p&gt;\tDate:\t\t\t06\/15\/2007&lt;\/p&gt;\r\n\t *  &lt;p&gt;\tProgrammer:\t\tLon Hosford: https:\/\/www.lonhosford.com&lt;\/p&gt;\r\n\t *  &lt;p&gt;\tChanges:\t\tOriginal programming&lt;\/p&gt;\r\n\t * *\/\t\r\n\tpublic class Circle extends Sprite {\r\n\t\t\/**\r\n\t\t * Radius of the circle. \r\n\t\t * @default 40\t\r\n\t\t * *\/\r\n\t\tprivate var _radius:Number;\r\n\t\t\/**\r\n\t\t * Fill color. \r\n\t\t * @default 0x000000\t\r\n\t\t * *\/\r\n\t\tprivate var _color:uint;\r\n\t\t\/**\r\n\t\t * Constructor.\r\n\t\t * @param radius See _radius\r\n\t\t * @param color See _color\r\n\t\t * *\/\r\n\t\tpublic function Circle(radius:Number=40, color:uint=0x000000) \r\n\t\t{\r\n\t\t\t_radius = radius;\r\n\t\t\t_color = color;\r\n\t\t\t\r\n\t\t\tinit();\r\n\t\t\t\r\n\t\t}\r\n\t\t\/**\r\n\t\t * Initialize the class\r\n\t\t * *\/\r\n\t\tpublic function init():void \r\n\t\t{\r\n\t\t\tdraw();\r\n\t\t}\r\n\t\t\/**\r\n\t\t * Draw class graphics\r\n\t\t * *\/\r\n\t\tpublic function draw():void \r\n\t\t{\r\n\t\t\tgraphics.clear();\r\n\t\t\tgraphics.beginFill(_color,alpha);\r\n\t\t\tgraphics.drawCircle(0, 0, _radius);\r\n\t\t\tgraphics.endFill();\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>By Lon (Alonzo) Hosford I was working through chapter 3 of Keith Peter&#8217;s Foundation Actionscript 3.0 Animation: Making Things Move and came up with this Rotator class that will revolve any sprite around a given point. [August 18 2010] I updated this to an ActionScript project to Flex Builder 4. Download the example code. You [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[19,12,30,49,41,42,43,45,44],"class_list":["post-679","post","type-post","status-publish","format-standard","hentry","category-general","tag-actionscript","tag-air-adobe-integrated-runtime","tag-animation","tag-keith-peters","tag-keyboardevent","tag-textfield","tag-textformat","tag-timer","tag-timerevent"],"_links":{"self":[{"href":"https:\/\/www.lonhosford.com\/lonblog\/wp-json\/wp\/v2\/posts\/679","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lonhosford.com\/lonblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lonhosford.com\/lonblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lonhosford.com\/lonblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lonhosford.com\/lonblog\/wp-json\/wp\/v2\/comments?post=679"}],"version-history":[{"count":29,"href":"https:\/\/www.lonhosford.com\/lonblog\/wp-json\/wp\/v2\/posts\/679\/revisions"}],"predecessor-version":[{"id":3714,"href":"https:\/\/www.lonhosford.com\/lonblog\/wp-json\/wp\/v2\/posts\/679\/revisions\/3714"}],"wp:attachment":[{"href":"https:\/\/www.lonhosford.com\/lonblog\/wp-json\/wp\/v2\/media?parent=679"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lonhosford.com\/lonblog\/wp-json\/wp\/v2\/categories?post=679"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lonhosford.com\/lonblog\/wp-json\/wp\/v2\/tags?post=679"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}