【问题标题】:How to Convert one Vector Data to another Vector Data in Actionscript 3.0如何在 Actionscript 3.0 中将一个矢量数据转换为另一个矢量数据
【发布时间】:2011-07-13 08:08:59
【问题描述】:
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]);

}

【问题讨论】:

  • 一些文本不可见,变量 igames:Vector 。 = 新向量。 ();

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


【解决方案1】:

有一种更方便的方法。

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

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

如需更多详细信息,请转至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

【讨论】:

  • 当我做 var igames:Vector. = Vector.(shootGames);它仍然显示游戏长度为零。
  • 您确定shootGames Vector 不为空吗?我在答案中添加了示例代码;当我运行它时,两个向量的长度相同。
  • 谢谢,我在 Vector 前面错误地使用了 new 关键字,导致了这个错误。
猜你喜欢
  • 1970-01-01
  • 2019-02-03
  • 1970-01-01
  • 1970-01-01
  • 2023-03-03
  • 2021-05-05
  • 2022-11-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多