我在网上找到了这段代码,他实现了我想要使用的特定动作。不幸的是,他使用的是数值而不是文本。我按照他的所有指示进行操作,但我尝试用数组替换 Vector,但收到错误消息。我收到的错误是“1199:非参数化类型的类型参数”。那是因为我添加了一个数组值而不是一个向量,这家伙已经做到了。他在他的教程中所拥有的数值是正确的。他还创建了一个名为 Item.as 的 .as 类。这是位于主时间轴中的新层中的 AS 代码,该层称为我的 .fla 文件的操作,名为 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;
}
}
}
同样如前所述,还有一个名为 Item.as 的 .as 类。这是在一个单独的文件中。代码如下:
package {
import flash.display.MovieClip;
public dynamic class Item extends MovieClip {
public function Item() {
}
}
}
如果您按照他的指示,它将适用于数值,但我想使用一个数组并将数组中的字符串值放在 Item 影片剪辑内,您将看到数值在圆形内. 我有他的 Rotating Menu 教程的链接,它有 9 个步骤。链接在这里:
感谢大家的帮助。我刚回到 ActionScript/Flash