The Custom AS3 SpinnerMenu Class

Below we list public methods of the SpinnerMenu class included in this tutorial. The class has changed greatly from its earlier version dated March 29, 2009. You can review the information given below or you can simply look at the source code in the files xmlspinner.fla and contained in the zip package to see how to use the class.

The SpinnerMenu class has the following public methods.

The constructor evoked with the key word 'new':

  • new SpinnerMenu(thumbs:Vector.<BitmapData>, pics:Vector.<String>,
        caps:Vector.<String>, n:int, cont:Sprite, ctf:TextField, itf:TextField, sp:int=2, px:Number=10)

The parameter 'thumbs' is a Vector of BitmapData objects corresponding to thumbnails. The second parameter, 'pics', is a Vector of Strings that contains addresses of images to be loaded as the user clicks on thumbnails. 'n' is an integer that dictates the number of tiles displayed at one time in the vertical menu; that is, in a column. 'cont' is a reference to an external Sprite into which large images will loaded as the user clicks on a thumbnail. 'ctf' is a reference to an external dynamic TextField into which captions will be loaded, 'itf' is a reference to an external dynamic TextField in which messages to the user are displayed about loading images. The last two parameters are optional. 'sp' gives the speed of rotation and has only three possible values: 1, 2, 3. 'px' gives the distance, in pixels, between tiles in the vertical column.

Loading images, captions, and messages into external DisplayObjects gives the SpinnerMenu greater flexibilty both for layout purposes and functionality. In our applet, for example, both instances load images into the same Sprite and TextFields.

For the menu to function properly, 'thumbs', 'pics' and 'caps' have to have the same number of elements, say 'elems'. Furthermore, 'n' has to be a factor of this number; that is, 'elems' must be divisible by 'n' without a remainder. Also, 'n' cannot equal 'elems'. For example, if you use 20 images, then 'n', the number of items in a column, can be equal to 1, 2, 4, 5, and 10. If you choose '1', you will have one spinning tile with 20 different images appearing on the reverse as the tile spins. If you choose '10', you will have 10 tiles with only two different images appearing as the menu spins. If the data comes from a properly constructed XML file as demonstarated on the previous page, all these conditions will be automatically satisfied.

  • doSpin(s:String):void

The parameter 's' is responsible for the direction of the spin. It can have two values "left" and "right". In our, example the direction is chosen randomly with each click on the arrow button.

  • loadInitial():void

The method, if called, will load the first image on the list without the user's click.


On the next page, we discuss public methods of the SpinnerMenu class.

Back to Flash CS4 Tutorials              Back to Flash and Math Home

We welcome your comments, suggestions, and contributions. Click the Contact Us link below and email one of us.

Adobe®, Flash®, ActionScript®, Flex® are registered trademarks of Adobe Systems Incorporated.