SitePoint Sponsor

# Thread: Problem with "Rotating Menu" in ActionScript 3.0

1. ## Problem with "Rotating Menu" in ActionScript 3.0

I'm using Adobe Flash CS4 professional for this Actionscript 3.0 project
(http://tutorials.flashmymind.com/200...ctionscript-3/)

I even tried following the suggestions in the comments as well but this error always shows up:
TypeError: Error #1010: A term is undefined and has no properties.
at rotating_menu_fla::MainTimeline/frame1()
(for complete details, kindly click the link - http://i429.photobucket.com/albums/q...eenshot_03.jpg)

I've been following every step of the tutorial but I'm stumped over the coding...
Here's the code by the way...
Code:
```//Save the center coordinates of the stage
var centerX:Number=stage.stageWidth/2;
var centerY:Number=stage.stageHeight/2;
//The number of items we will have (feel free to change!)
var NUMBER_OF_ITEMS:uint=5;
//Radius of the menu circle (horizontal and vertical)
var radiusX:Number=200;
var radiusY:Number=100;
//Angle difference between the items (in radians)
var angleDifference:Number = Math.PI * (360 / NUMBER_OF_ITEMS) / 180;
//How fast a single circle moves (we calculate the speed
//according to the mouse position later on...)
var angleSpeed:Number=0;
//Scaling speed of a single circle
var scaleSpeed:Number=0.0002;
//This vector holds all the items
//(this could also be an array...)
var itemVector:Array = new Array ('1', '2', '3', '4','5');
//This loop creates the items and positions them
//on the stage
for (var i:uint = 0; i < NUMBER_OF_ITEMS; i++) {
//Create a new menu item
var item:Item = new Item();
//Get the angle for the item (we space the items evenly)
var startingAngle:Number=angleDifference*i;
//Set the x and y coordinates
item.x=centerX+radiusX*Math.cos(startingAngle);
item.y=centerY+radiusY*Math.sin(startingAngle);
//Save the starting angle of the item.
//(We have declared the Item class to be dynamic. Therefore,
//we can create new properties dynamically.)
item.angle=startingAngle;
//Add an item number to the item's text field
item.itemText.text=i.toString();
//Allow no mouse children
item.mouseChildren=false;
//Add the item to the vector
itemVector.push(item);
//Add the item to the stage
addChild(item);
}
//We use ENTER_FRAME to animate the items
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
//This function is called in each frame
function enterFrameHandler(e:Event):void {
//Calculate the angle speed according to mouse position
angleSpeed = -(mouseX - centerX) / 5000;
//Loop through the vector
for (var i:uint = 0; i < NUMBER_OF_ITEMS; i++) {
//Save the item to a local variable
var item:Item=itemVector[i];
//Update the angle
item.angle+=angleSpeed;
//Set the new coordinates
item.x=centerX+radiusX*Math.cos(item.angle);
item.y=centerY+radiusY*Math.sin(item.angle);
//Calculate the vertical distance from centerY to the item
var dy:Number=centerY-item.y;
//Scale the item according to vertical distance
item.scaleY = (dy / radiusY)+2;
//Set the x scale to be the same as y scale
item.scaleX=item.scaleY;
//Adjust the alpha according to y scale
item.alpha=item.scaleY+1.1;
}
}```
I find it odd - it may be that the code is right but I don't know if these steps
Code:
```has messed up the project...
3. Convert the circle into a movie clip...
4. In the “Item” movie clip, create a dynamic text field in the center of the circle (in a new layer). Set the text to align center. Type some number in the text field.
5. Give the text field an instance name of “itemText”. Embed numerals...
6. Remove the Item movie clip from the stage. We will create all the items dynamically via ActionScript 3.```
Here are what I've done below...
http://i429.photobucket.com/albums/q...eenshot_02.jpg
http://i429.photobucket.com/albums/q...eenshot_01.jpg

I have to admit that the steps 3 to 6 is confusing and didn't made sense to me - especially with step six, when you have to remove the movie clip from the stage. For me, if I were to do that, what would the script work on then?

Any idea what I did wrong?

2. If the movieClip is removed from stage, if it is linked in the library and has a class assigned then you can refer to it and dynamically create new instances of it

3. So it means there was no need for me to append an actionscript to the main timeline then?

Come to think of it, there was a part there that told me to create a custom class for that (kindly see below...)
Code:
```	package {
import flash.display.MovieClip;
public dynamic class Item extends MovieClip {
public function Item() {
}
}
}```
You mentioned that I can refer the code above to the movie clip - but the tutorial didn't clearly say how. There was a section that said so (I guess it was the part after having coded the class script...) but things didn't turn out for the movie in spite of that...

How would I refer to it then via the Flash interface? Pardon me about this - all the info from that article confounded things for me

4. Thanks, I realized my mistake - thanks for the tip :-)

But now, I tried to modify the code of this tutorial a bit to have words appear inside the circles (like "Home", "About", etc....) like what I've typed in the line in the screenschot -
http://i429.photobucket.com/albums/q...eincode_00.jpg

But inspite of what I believe are the appropriate changes I've done, an error showed up still -
(kindly see here -
http://i429.photobucket.com/albums/q...rincode_00.jpg)

Why is that happening?
Before I forget, in what section of the code must I insert a line that will make a clicked button display the info corresponding to it? (that is, if I click on the "Contact" or any of the buttons a window will appear beneath the menu on the stage...)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•