如何在Actionscript 3.0中将一个矢量数据转换为另一个矢量数据

时间:2011-03-11 08:30:54

标签: actionscript-3 flex3 flex4 flash-cs4 flash-cs5

Class ShootGame implements IGame
{

}

//ShootGame Vector 

 var shootGames:Vector.<ShootGame> = new Vector.<ShootGame>();
for(i=0;i<20;i++)
{
   shootGames.push(new ShootGame());
}



var igames:Vector.<IGame> = //What is the Simplest method to convert ShootGame to IGame Vector

//I am doing like

igames = new Vector.<IGame>();

for(i=0;i < shootGames.length;i++)
{

igames.push(shootGames[i]);

}

1 个答案:

答案 0 :(得分:1)

有一种更方便的方法。

var igames:Vector.<IGame> = Vector.<IGame>(shootGames);

请注意,当您使用“Vector。&lt; IGame&gt;(shootgames)”时,您没有进行类型转换,而是创建一个新的Vector实例并使用“shootGames”Vector的内容填充它。

有关详细信息,请转到here

示例代码:

var shootGames:Vector.<ShootGame> = new Vector.<ShootGame>();
for (var i:int = 0; i < 20; i++) {
    shootGames.push(new ShootGame());
}

var igames:Vector.<IGame> = Vector.<IGame>(shootGames);

trace("shootGames.length", shootGames.length); //20
trace("igames.length", igames.length); //20