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

发布于 2024-10-21 09:11:50 字数 455 浏览 1 评论 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 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]);

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

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

向地狱狂奔 2024-10-28 09:11:50

有一种更方便的方法可以做到这一点。

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

请注意,当您使用“Vector.< IGame >(shootgames)”时,您并不是在进行类型转换,而是创建一个新的 Vector 实例并用“shootGames”矢量的内容填充它。

有关更多详细信息,请访问此处。

示例代码:

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文