Actionscript 3 在flash CS6 ActionScript 3.0中射击子弹

Actionscript 3 在flash CS6 ActionScript 3.0中射击子弹,actionscript-3,flash,Actionscript 3,Flash,当我以3.0的速度在Flash CS6中进行射击时,我不断地得到以下错误 1118:将具有静态类型对象的值隐式强制到可能不相关的类型flash。显示:DisplayObject 包 { 导入flash.display.MovieClip; 导入flash.ui.Mouse; 导入flash.utils.Timer; 导入flash.events.TimerEvent; 导入flash.ui.Keyboard; 导入flash.events.KeyboardEvent; 导入flash.event

当我以3.0的速度在Flash CS6中进行射击时,我不断地得到以下错误

1118:将具有静态类型对象的值隐式强制到可能不相关的类型flash。显示:DisplayObject

包
{
导入flash.display.MovieClip;
导入flash.ui.Mouse;
导入flash.utils.Timer;
导入flash.events.TimerEvent;
导入flash.ui.Keyboard;
导入flash.events.KeyboardEvent;
导入flash.events.Event;
导入flash.events.MouseEvent;
导入flash.media.SoundChannel;
公共类AvoiderGame扩展了MovieClip
{
公共军队:阵列;
公共变量重新启动:重新启动;
公敌:敌人;
公共虚拟现实:虚拟现实;
公共变量gameTimer:计时器;
公共变量useMouseControl:Boolean;
public-var下键:Boolean;
公共变量项目符号:数组=[];
公共背景音乐:背景音乐;
公共var-enemySound:enemySound;
公共var bgmSoundChannel:SoundChannel;
公共频道:SoundChannel;
函数AvoiderGame()
{
/*useMouseControl=false;
downKey=false;
如果(使用鼠标控制)
{
avatar.x=鼠标;
avatar.y=老鼠;
}
其他的
{
化身x=200;
化身y=250;
}
*/
背景音乐=新背景音乐();
bgmSoundChannel=backgroundMusic.play();
bgmSoundChannel.addEventListener(Event.SOUND_COMPLETE,onbackgroundmusic finished);
enemySound=新的enemySound();
陆军=新阵列();
//敌人的初始位置
var new敌军=新敌军(2700600);
军队。推(新敌人);
addChild(新敌人);
阿凡达=新阿凡达();
addChild(阿凡达);
化身高度=220;
头像宽度=120;
avatar.addEventListener(MouseEvent.CLICK,shoot);
游戏计时器=新计时器(25);
gameTimer.addEventListener(TimerEvent.TIMER,onTick);
gameTimer.start();
//addEventListener(Event.ADDED_TO_STAGE,onAddToStage);
}//结束回避
功能射击(e:MouseEvent):无效
{ 
变量b:快照=新快照();
b、 addEventListener(Event.ENTER_FRAME,Bullettflies);
第二阶段:儿童(b);
子弹。推(b);
}
功能公告(e:事件):无效
{
e、 当前目标y-=5;
如果(e.currentTarget.y<0 | | e.currentTarget.y>stage.height)
{
阶段。removeChild(如currentTarget);
项目符号.拼接(项目符号.索引of(e.currentTarget),1);
}
}
背景音乐公共功能结束(事件:事件):无效
{
bgmSoundChannel=backgroundMusic.play();
bgmSoundChannel.addEventListener(Event.SOUND_COMPLETE,onbackgroundmusic finished);
}
公用函数onKeyPress(keyboardEvent:keyboardEvent):无效
{
if(keyboardEvent.keyCode==Keyboard.DOWN)
{
downKey=true;
}
}
公用函数onKeyRelease(keyboardEvent:keyboardEvent):无效
{
if(keyboardEvent.keyCode==Keyboard.DOWN)
{
downKey=false;
}
}
AddToStage上的公共函数(事件:事件):无效
{
stage.addEventListener(KeyboardEvent.KEY_DOWN,onKeyPress);
stage.addEventListener(KeyboardEvent.KEY\u UP,onKeyRelease);
}
公共函数onTick(timerEvent:timerEvent):无效
{
if(Math.random()<2800)
{
var randomY:Number=Math.random()*2800;
var NEWYOUNT:敌人=新敌人(宽度,随机);
军队。推(新敌人);
addChild(新敌人);
gameScore.addToValue(1);
//sfxSoundChannel=enemySound.play();
}//End if语句
/*
如果(使用鼠标控制)
{
avatar.x=鼠标;
avatar.y=老鼠;
}
其他的
{
如果(向下键)
{
avatar.moveDown();
}
}
*/
avatar.x=鼠标;
avatar.y=老鼠;
每个(var敌人:军队中的敌人)
{
敌人。移动可移动();
如果(化身.命中测试对象(敌人))
{
bgmSoundChannel.stop();
gameTimer.stop();
dispatchEvent(新AvatarEvent(AvatarEvent.DEAD));
}//End if语句
}//循环结束
}//结束点选函数
公共函数getFinalScore():编号
{
返回gameScore.currentValue;
}
}//结束AvoiderGame课程
}//端包

只是一个猜测:在你说
addChild(b)
之前,你已经开始了ENTER\u FRAME循环(它将删除“b”)。尝试将“b”放在显示列表上b
package 
    {
        import flash.display.MovieClip;
        import flash.ui.Mouse;
        import flash.utils.Timer;
        import flash.events.TimerEvent;
        import flash.ui.Keyboard;
        import flash.events.KeyboardEvent;
        import flash.events.Event;
        import flash.events.MouseEvent;
        import flash.media.SoundChannel;

        public class AvoiderGame extends MovieClip 

        {

            public var army:Array;
            public var reishoot:ReiShoot;
            public var enemy:Enemy;
            public var avatar:Avatar;
            public var gameTimer:Timer;
            public var useMouseControl:Boolean;
            public var downKey:Boolean;
            public var bullets:Array = [];
            public var backgroundMusic:BackgroundMusic;
            public var enemySound:EnemySound;
            public var bgmSoundChannel:SoundChannel;
            public var sfxSoundChannel:SoundChannel;


             function AvoiderGame() 
            {
                /*useMouseControl = false;
                downKey = false;

                if( useMouseControl )
                {
                    avatar.x = mouseX;
                    avatar.y = mouseY;

                }
                else
                {
                    avatar.x = 200;
                    avatar.y = 250;

                }
                */

                backgroundMusic = new BackgroundMusic();
                bgmSoundChannel = backgroundMusic.play();
                bgmSoundChannel.addEventListener( Event.SOUND_COMPLETE, onBackgroundMusicFinished );
                enemySound = new EnemySound();
                army = new Array();
                //Initial Position of the Enemy
                var newEnemy = new Enemy( 2700, 600 );

                army.push( newEnemy );
                addChild( newEnemy );

                avatar = new Avatar();
                addChild( avatar );


                avatar.height = 220;
                avatar.width = 120;

                avatar.addEventListener(MouseEvent.CLICK, shoot);
                gameTimer = new Timer( 25 );
                gameTimer.addEventListener( TimerEvent.TIMER, onTick );
                gameTimer.start();

                //addEventListener( Event.ADDED_TO_STAGE, onAddToStage );
            }//End AvoiderGame

            function shoot(e:MouseEvent):void
            { 

                 var b:Shot = new Shot();
                 b.addEventListener(Event.ENTER_FRAME, bulletflies);
                 stage.addChild(b);
                 bullets.push(b);
            }

            function bulletflies(e:Event):void
            {
                 e.currentTarget.y -= 5;
                 if(e.currentTarget.y < 0 || e.currentTarget.y > stage.height) 
                    {
                         stage.removeChild(e.currentTarget);
                         bullets.splice(bullets.indexOf(e.currentTarget), 1);
                    }
            }

            public function onBackgroundMusicFinished( event:Event ):void
            {
                bgmSoundChannel = backgroundMusic.play();
                bgmSoundChannel.addEventListener( Event.SOUND_COMPLETE, onBackgroundMusicFinished );
            }

            public function onKeyPress(keyboardEvent:KeyboardEvent):void
            {
                    if ( keyboardEvent.keyCode == Keyboard.DOWN )
                    {
                        downKey = true;
                    }
            }

            public function onKeyRelease( keyboardEvent:KeyboardEvent ):void
            {
                    if ( keyboardEvent.keyCode == Keyboard.DOWN )
                    {
                        downKey = false;
                    }
            }

            public function onAddToStage(event:Event):void
            {

                stage.addEventListener( KeyboardEvent.KEY_DOWN, onKeyPress );
                stage.addEventListener( KeyboardEvent.KEY_UP, onKeyRelease );
            }



            public function onTick( timerEvent:TimerEvent ):void 
            {
                if ( Math.random() < 2800 )
                {
                    var randomY:Number = Math.random() * 2800;
                    var newEnemy:Enemy = new Enemy( width, randomY );
                    army.push( newEnemy );
                    addChild( newEnemy );
                    gameScore.addToValue( 1 );
                    //sfxSoundChannel = enemySound.play();
                }//End if statement
                /*
                if( useMouseControl )
                {
                    avatar.x = mouseX;
                    avatar.y = mouseY;
                }

                else
                {
                    if ( downKey )
                    {
                        avatar.moveDown();
                    }
                }
                */
                avatar.x = mouseX;
                avatar.y = mouseY;



                for each ( var enemy:Enemy in army ) 
                {
                    enemy.moveDownABit();
                    if ( avatar.hitTestObject( enemy ) ) 
                    {
                        bgmSoundChannel.stop();
                        gameTimer.stop();
                        dispatchEvent( new AvatarEvent( AvatarEvent.DEAD ) );
                    }//End if statement
                }//End for loop
            }//End onTick function

            public function getFinalScore():Number
            {
                return gameScore.currentValue;
            }


        }//End AvoiderGame class
    }//End package
stage.removeChild(e.currentTarget as DisplayObject);