AS3 Polar Coordinates and Radians


Many times I’ve set up interfaces where I need to place different objects equidistant around a central object. The solution to this problem is to first calculate the angle of each object by converting Radians to Degrees. This can be expressed by the following formula


So, you simply need to loop through your collection of objects and assign each a different angle. After that you plug that angle into a new Polar Point.

for(var i=0;i

Here’s the complete source:

        import flash.ui.*;
        import flash.display.*;
        import flash.geom.*;

        public class Main extends Sprite

                | Private Variables                         | Data Type

                private var array:Array = new Array()
                private var circumference:int;

                | Constructor

                public function Main ()
                        stage.align = StageAlign.TOP_LEFT;

                        // make some balls
                        addParticle( 100 )

                        menu.txtParticles.text = 'Particles: 100';

                        stage.addEventListener( Event.ENTER_FRAME, runParticle )

                        menu.slideCircumference.addEventListener( Event.CHANGE, changeCircumference );
                        menu.particles.addEventListener( Event.CHANGE, changeParticles );


                private function addParticle( num )
                        stage.removeEventListener( Event.ENTER_FRAME, runParticle )

                        var tot:Number = array.length

                        // kill mc's
                        for( var t=0;t


AS3 Drop Down Menu Class

I briefly Googled for a drop down class to no avail. I say briefly as I only went one page deep. I’m sure there are others out there, but I instead got impatient as usual and just wrote my own. I thought I’d share it for other impatient people’s benefit. Without further ado here’s the AS3 Drop Down Class code. It’s a work in progress and most likely will be updated when I give it any more thought.

You can see the drop down in use on my homepage.

Edit [ 12.16.08 ] : added directional code.

// array for drop
var dropOtherArray:Array = new Array()
dropOtherArray.push( {title:"iWork", name:"folio"} )
dropOtherArray.push( {title:"iExperiment", name:"lab"} )
dropOtherArray.push( {title:"iWrite", name:"blog"} )
dropOtherArray.push( {title:"iPhotograph", name:"photo"} )
dropOtherArray.push( {title:"iFlickr", name:"flickr"} )
dropOtherArray.push( {title:"iRecord", name:"vimeo"} )
dropOtherArray.push( {title:"contactMe", name:"contact"} )

fmat.color = 0xffffff
fmat.font = font.fontName
fmat.size = 11

addChild( _dropOther = new DropDown( 180, 25, "iLiveElsewhere:", fmat, 0x000033, dropOtherArray, "down", other ) )

package com.teso.ui
        import com.gskinner.motion.*
        import flash.display.*;
        import flash.utils.*;
        import flash.text.*;
        import fl.transitions.*;
        import fl.transitions.easing.*;

        public class DropDown extends Sprite
                private var _items:Array = new Array()
                private var _overC:uint;
                private var _backC:uint;
                private var _w:Number;
                private var _h:Number;
                private var _timer:Timer;
                private var _open:Boolean = false;
                private var _defaultText:TextField;
                private var _title:String;
                private var _direction:String;
                private var _fmt:TextFormat;

                public function DropDown( w:Number, h:Number, title:String, fmt:TextFormat, colorBack:uint, itemArray:Array, direction:String, callback )
                        // timer
                        _timer = new Timer( 300 );
                        _timer.addEventListener( TimerEvent.TIMER, closeDrop )

                        // vars
                        _w = w
                        _h = h
                        _backC = colorBack
                        _items = itemArray
                        _title = title
                        _direction = direction
                        _fmt = fmt

                        // create a back for the holder
                        var holder:MovieClip = new MovieClip();
               = "holder"
               _backC, 1 );
               0, 0, _w, _h, 2, 2 )

                        // add the drop
                        addChild( holder )

                        // set listeners
                        holder.buttonMode = true;
                        holder.addEventListener( MouseEvent.MOUSE_OVER, openDrop )
                        holder.addEventListener( MouseEvent.MOUSE_OVER, cancelClose )
                        holder.addEventListener( MouseEvent.MOUSE_OUT, startClose )

                        // create a text field
                        var t:TextField = new TextField()
               = "holderText"
                        t.selectable = false;
                        t.autoSize = TextFieldAutoSize.LEFT;
                        t.htmlText = title
                        t.setTextFormat( fmt )
                        t.y = ( holder.height/2 ) - ( t.height/2 )

                        _defaultText = t

                        // add the text
                        holder.addChild( t )

                        // create children
                        for( var i=0; iPermalink: