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]);
}
答案 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