开发者

How to Convert one Vector Data to another Vector Data in Actionscript 3.0

Class ShootGame implements IGame
{

}

//ShootGame Vector 

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



var iga开发者_StackOverflow社区mes: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]);

}


There is a more convenient way to do that.

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

Notice that when you use "Vector.< IGame >(shootgames)" you are not making a typecast, instead you are creating a new Vector instance and populating it with the content of the "shootGames" Vector.

For more detailed information, go here.

Sample code:

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜