Home Tutorials Forums Articles Blogs Movies Library Employment Press

 ActionScript.org Forums Dynamically Moving an Object Along a Circle Motion Guide
 Register FAQ Members List Social Groups Calendar Search Today's Posts Mark Forums Read

 07-05-2005, 06:13 PM #1 dr_nick_riviera Registered User   Join Date: Jul 2005 Posts: 2 Dynamically Moving an Object Along a Circle Motion Guide Hi everybody, I'm trying to move an object along circlular motion guide dynamically using two buttons -- a left button, when pressed down, will move the object counter clockwise, and the right button clockwise. Does anyone know how I can achieve this? Thanks, -Dr.NickRiviera
 02-19-2009, 11:14 PM #2 anticipatient Registered User   Join Date: Feb 2009 Posts: 16 Well you can create circular motion using sin for y position and cos for x position. Where radX and radY are the radius of the circle (use different values to make an oval), and centerX and centerY are the coordinates for the center of the circle, your code would look like this: ActionScript Code: ```var angle:Number = 0; var radX:Number = 50; var radY:Number = 50; var centerX:Number = 200; var centerY:Number = 200; var orbitSpeed:Number = .05; onEnterFrame(){ object._x = centerX+Math.cos(angle)*radX; object._y = centerY+Math.sin(angle)*radY; var angle += orbitSpeed; }``` If you're going to use the right mouse button in a flash movie, you should disable the context menu that pops up when you right click. I forget how to do that, but it shouldn't be too hard for you to find. That aside, though, one way you could do this (and there may be better ways -- I'm a beginner) is an if() statement within the onEnterFrame function: ActionScript Code: ```var LMB:Boolean = false; onMouseDown = function(){ LMB = true; } onEnterFrame(){ if(LMB == true){     object._x = centerX+Math.cos(angle)*radX;     object._y = centerY+Math.sin(angle)*radY; } }``` To make it stop moving when you let the button up, just add: ActionScript Code: ```onMouseUp = function(){ LMB = false; }``` I don't know how to use the right mouse button, but say it was "onRightMouseDown," you'd add this: ActionScript Code: ```var RMB:Boolean = false; onRightMouseDown = function(){ RMB = true; LMB = false; }``` And then you should also add, under onMouseDown, ActionScript Code: `RMB = false;` Finally, you'd have to change things so that when the right button was pressed, the circle would go the other way. That would be as simple as switching "sin" and "cos" I am new, so there may be mistakes in this, but the whole thing should look like this (there's probably an extra bracket or missing bracket in here too, so watch out ActionScript Code: ```var angle:Number = 0; var radX:Number = 50; var radY:Number = 50; var centerX:Number = 200; var centerY:Number = 200; var orbitSpeed:Number = .05; var LMB:Boolean = false; var RMB:Boolean = true; onMouseDown = function(){ LMB = true; RMB = false; } onRightMouseDown = function(){ LMB = false; RMB = true; } onEnterFrame(){ if(LMB == true){ object._x = centerX+Math.cos(angle)*radX; object._y = centerY+Math.sin(angle)*radY; var angle += orbitSpeed; } if(RMB == true){ object._x = centerX+Math.sin(angle)*radX; object._y = centerY+Math.cos(angle)*radY; var angle += orbitSpeed; } }```
 02-20-2009, 02:02 AM #3 Xegnma Senior Member   Join Date: Sep 2007 Posts: 114 A simple approach is to create a container clip for your object, embed the object in the container via attachMovie and then rotate the container clip. You can do this using the authoring environment or dynamically using the code below. Code: ```var radius:Number = 10; var container:MovieClip = this.createEmptyMovieClip("_container", this.getNextHighestDepth()); container.attachMovie("objectLinkageID","instanceName",container.getNextHighestDepth(), {_x:radius});``` To set up your buttons you could do the following: Code: ```var increment:Number = 4; cwButton.onPress = function(): Void { _parent.onEnterFrame = function(): Void { container._rotation += increment; } } ccwButton.onPress = function():Void { _parent.onEnterFrame = function(): Void { container._rotation -= increment; } } cwButton.onRelease = ccwButton.onRelease = function(): Void { delete _parent.onEnterFrame; }```

 Thread Tools Display Modes Rate This Thread Linear Mode Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is Off HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home ActionScript Forums Group     ActionScript 3.0     ActionScript 2.0     ActionScript 1.0 (and below)     Simple Stuff (Newbies) Flash General Questions     Flash 10 General Questions     Flash 9 General Questions     Flash 8 General Questions     Other Flash General Questions Flex     Flex 2, 3 & 4     Flex 1 Extensions and Plugins     Components     JSFL - Extending Flash Desktop, Mobile and non-browser Environments     AIR (Apollo)     FlashLite / Portable Devices Development     Projectors and CDs Supporting Technologies     HTML and JavaScript     haXe     Server-Side Scripting     Flash Remoting     Flash Media Server General     Best Practices     Gaming and Game Development     Animation and Effects     Flashants Support Forum Community Boards     General Chat     Just for Kicks Challenges     Detention Flash In Action     Site Check     Cool Sites     Widgets Decommissioned     Projects and Positions CMS Forums     Announcements Board     Content Postings / Updates     Product Review Requests     CMS Technical Questions     Process Questions     Collaboration & Suggested Articles

All times are GMT. The time now is 11:45 AM.

///