我正在尝试保留一个静态数组列表,以便在需要时可以在我的闪存应用程序中全局调用它,但是它似乎没有将任何值添加到数组列表中。
package com.globals
{
import com.player.PlayerBullets;
import com.ships.enemy.SpaceDrone;
import com.globals.Globals;
import flash.display.MovieClip;
public class MCActiveLibrary
{
private static var enemyShips:Array = new Array();
private static var enemyBullets:Array = new Array();
private static var playBullets:Array = new Array();
public static function addPlayerBullets(bullets:PlayerBullets):void
{
playBullets.push(bullets);
trace(playBullets[1]);
bullets.id = playBullets.length -=1;
trace("array Length:"+ bullets.id + "\nbullet ID:"+playBullets.length+"\n");
Globals._stage.addChild(bullets);
}
public static function getPlayerBullets(i:int):PlayerBullets
{
return playBullets[i];
}
public static function removePlayerBullets(i:int):void
{
trace(i);
Globals._stage.removeChild(playBullets[i]);
//updatePositions(playerBullets, i+1);
//playerBullets.splice(i, 1);
}
}
我得到的运行时错误是..
TypeError:错误 #2007:参数 child 必须为非空。在 flash.display::DisplayObjectContainer/removeChild() 在 com.globals::MCActiveLibrary$/removePlayerBullets()[H:\HobbyProject\SpaceDevils\com\globals\MCActiveLibrary.as:28] 在 com.player::PlayerBullets/eFrame ()[H:\HobbyProject\SpaceDevils\com\player\PlayerBullets.as:30]
至于正在运行的跟踪命令
[object PlayerBullets] 数组长度:0 子弹 ID:0 0
这让我有点难过,特别是考虑到在数组的位置 0 找到了对象 PlayerBullets,即使数组长度为 0。
非常感谢任何人都可以提供的帮助!