我在网上发现了这个代码,他实现了我想要使用的特定运动。不幸的是,他使用的是数值而不是文本。我遵循了他的所有说明,但我尝试用数组替换Vector,并收到错误消息。我收到的错误是“1199:带有非参数化类型的类型参数”。这是因为我添加了一个数组值,而不是这个人所做的向量。他在教程中的内容对数值是正确的。他还创建了一个名为Item.as的.as类。这里是AS代码是在主时间轴在一个叫新层叫做rotate.fla我FLA文件的动作:AS3围绕修复图像旋转文本
//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.。至于类这是在一个单独的文件。代码如下:
package {
import flash.display.MovieClip;
public dynamic class Item extends MovieClip {
public function Item() {
}
}
}
如果你按照他的指示,它会为一个数值工作,但我想用一个数组,将字符串值从数组中项的影片剪辑,其中的内你会看到数字值都在圆形的内部。我有链接到他的旋转菜单教程,它是9个步骤。这里是链接:
感谢大家的帮助。我刚回到ActionScript/Flash
嘿,这对我有用。非常感谢。还有一个问题给你。当我启动它时,它显示了一个重复的值(假设字母a出现两次),是否在显示项目数量的循环值内? – DC724 2012-01-03 16:38:40
我不太明白你的意思是重复的价值。它在哪里出现? – 31eee384 2012-01-04 18:29:32
一旦你运行动画就会显示出来。所以说我有一个向量大小为9,并且值显示在0和1位置(0 =“a”1 =“a”)。你可以写一个for循环来检查vector中的重复值并推出一个重复值。 – DC724 2012-01-04 19:23:41