actionscript-3flash-cs5text-rotation

AS3 Rotating Text around a fix image


I found this code online and he achieved a particular movement I want to use. Unfortunately, he's using numerical values instead of text. I followed all of his instructions, but I tried to replace the Vector with an array, and received an error. The error I have been receiving is "1199:type parameters with a non-parameterized type." That's because I added an array value instead of an vector, which this guy has done. What he has in his tutorial is correct with numerical values. Also he created a .as class called Item.as. Here is the AS code that is in the main timeline in a new layer called actions of my .fla file called rotate.fla:

   //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=6;

   //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.<Item>=new Array('1', '2', '3', '4', '5').<Item>;

   //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 dymamic. 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);

    //If we are above centerY, double the y scale
    if (item.y<centerY) {
        item.scaleY*=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;

     }



       }

  }

Also as stated there is a .as class called Item.as. This is in a seperate file. The code is as follows:

package {
import flash.display.MovieClip;
public dynamic class Item extends MovieClip {
    public function Item() {
       }
      }
     }

If you follow his directions, it'll work for a numerical value, but I want to use an array and put the string values from the array inside of the Item movie clip where you will all see the numerical values are inside of the circle shape. I have the link to his Rotating Menu tutorial where it's 9 steps. Here is the link:

Rotating Menu

Thank you all for your help. I just got back into ActionScript/Flash


Solution

  • Erk, just read the tutorial you linked to, and changing from a Vector to a Array (which I don't recommend) seems to be the least of your concerns. I suggest you leave it as a Vector (it's more efficient, and the static typing does nothing but help in this case) and leave most of the code as-is. The code you need to change is this:

    //Add an item number to the item's text field
    item.itemText.text=i.toString();
    

    item.itemText.text actually holds a String, so you're in the clear there. What's happening is that you're converting i (the index of that Item in the vector) to a String so it can be displayed. Now you've got to change it so that it shows what you want.

    There are a bunch of ways to do that--since you're using the Flash program, you can actually use built-in stuff! Since Item extends MovieClip, you can replace the line earlier with:

    //Changes the item's frame to the same as its index
    item.gotoAndStop(i);
    

    Then in the authoring environment (Flash) make it have a different frame for each menu item.

    Hope this helps!

    I left in my description of how to change from a Vector to an Array below, just in case you have a reason to do so. Note: what I said above assumes you have NOT made this modification.


    I haven't read through all that code, but it looks like the issue is here:

    //This vector holds all the items
    //(this could also be an array...)
    var itemVector:Array.<Item>=new Array('1', '2', '3', '4', '5').<Item>;
    

    The .<Item> syntax only works for vectors, so you need to get rid of that. This line would look like this for an Array:

    var itemVector:Array = new Array('1', '2', '3', '4', '5');
    

    The code may have more problems, but this specifically addresses the error you mention.