2011-12-30 40 views
1

我在网上发现了这个代码,他实现了我想要使用的特定运动。不幸的是,他使用的是数值而不是文本。我遵循了他的所有说明,但我尝试用数组替换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个步骤。这里是链接:

Rotating Menu

感谢大家的帮助。我刚回到ActionScript/Flash

回答

0

Erk,刚刚阅读您链接到的教程,并从Vector更改为Array(我不建议)似乎是您最担心的问题。我建议你把它作为Vector(它更有效率,静态类型在这种情况下只会有帮助),并保留大部分代码。你需要改变的代码是这样的:

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

item.itemText.text实际持有String,让你在明确有很。发生了什么事是你要将i(向量中的Item的索引)转换为String,以便它可以显示。现在你必须改变它,以便显示你想要的东西。

有很多方法可以做到这一点 - 因为您使用的是Flash程序,所以您实际上可以使用内置的东西!由于Item延伸MovieClip,您可以用替换早一行:

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

然后在创作环境(闪存)使其具有每个菜单项不同的帧。

希望这会有所帮助!

我在我的描述中如何从Vector更改为Array,以防万一您有理由这样做。注意:我上面所说的假设你没有做这个修改。


我没有经历过所有的代码读取,但它看起来像这个问题是在这里:

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

.<Item>语法只适用于矢量,所以你需要摆脱的那个。这条线看起来像这样的阵列:

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

该代码可能有更多的问题,但这具体解决您提到的错误。

+0

嘿,这对我有用。非常感谢。还有一个问题给你。当我启动它时,它显示了一个重复的值(假设字母a出现两次),是否在显示项目数量的循环值内? – DC724 2012-01-03 16:38:40

+0

我不太明白你的意思是重复的价值。它在哪里出现? – 31eee384 2012-01-04 18:29:32

+0

一旦你运行动画就会显示出来。所以说我有一个向量大小为9,并且值显示在0和1位置(0 =“a”1 =“a”)。你可以写一个for循环来检查vector中的重复值并推出一个重复值。 – DC724 2012-01-04 19:23:41