Actionscript 3 错误#1034:类型强制失败:无法转换闪存。显示::Stage@27dfe089flash.display.MovieClip

Actionscript 3 错误#1034:类型强制失败:无法转换闪存。显示::Stage@27dfe089flash.display.MovieClip,actionscript-3,flash,actionscript,Actionscript 3,Flash,Actionscript,这里是错误>>类型错误:错误#1034:类型强制失败:无法转换闪存。显示::Stage@261b4089要闪烁.display.MovieClip。 com.ply::Heli/firebill() 在com.ply::Heli/myOnPress()上 这是Heli的班级: package com.ply { import flash.display.MovieClip; import flash.display.*; import flash.events.Event; import fl

这里是错误>>类型错误:错误#1034:类型强制失败:无法转换闪存。显示::Stage@261b4089要闪烁.display.MovieClip。 com.ply::Heli/firebill() 在com.ply::Heli/myOnPress()上

这是Heli的班级:

package com.ply 
{
import flash.display.MovieClip;
import flash.display.*;
import flash.events.Event;
import flash.events.KeyboardEvent;


import flash.ui.Keyboard;
import com.peluru.Bullet;

public class Heli extends MovieClip
{
    var shotCooldown:int;
    const MAX_COOLDOWN = 10;
    //Settings
    public var xAcceleration:Number = 0;
    public var yAcceleration:Number = 0;
    private var xSpeed:Number = 0;
    private var ySpeed:Number = 0;

    private var up:Boolean = false;
    private var down:Boolean = false;
    private var left:Boolean = false;
    private var right:Boolean = false;

    public function Heli()
    {
        shotCooldown = MAX_COOLDOWN;
        bullets = new Array();
        addEventListener(Event.ENTER_FRAME, update);
        addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
        init();
    }

    public function onAddedToStage(event:Event):void 
    {
        removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
        stage.addEventListener(KeyboardEvent.KEY_DOWN, myOnPress);
        stage.addEventListener(KeyboardEvent.KEY_UP, myOnRelease);
        init();
    }


    private function init():void
    {
        addEventListener(Event.ENTER_FRAME, RunHeli);           
    }

    private function RunHeli(event:Event):void
    {
        xSpeed += xAcceleration ;       //increase the speed by the acceleration
        ySpeed += yAcceleration ;       //increase the speed by the acceleration

        xSpeed *= 0.95;                 //apply friction
        ySpeed *= 0.95;                 //so the speed lowers after time

        if(Math.abs(xSpeed) < 0.02)     //if the speed is really low
        {
            xSpeed = 0;                 //set it to 0
                                //Otherwise I'd go very small but never really 0
        }
        if(Math.abs(ySpeed) < 0.02)     //same for the y speed
        {
            ySpeed = 0;
        }

        xSpeed = Math.max(Math.min(xSpeed, 10), -10);       //dont let the speed get bigger as 10
        ySpeed = Math.max(Math.min(ySpeed, 10), -10);       //and dont let it get lower than -10

        this.x += xSpeed;               //increase the position by the speed
        this.y += ySpeed;               //idem

    }

    public function update(e:Event){
    shotCooldown-- ;
    }

    /**
     * Keyboard Handlers
     */
    public function myOnPress(event:KeyboardEvent):void
    {
        if(event.keyCode == Keyboard.LEFT)
        {
            xAcceleration  = -1;
        }
        else if(event.keyCode == Keyboard.RIGHT)
        {
            xAcceleration  = 1;
        }
        else if(event.keyCode == Keyboard.UP)
        {
            yAcceleration  = -1;
        }
        else if(event.keyCode == Keyboard.DOWN)
        {
            yAcceleration  = 1;
        }
        else if (event.keyCode == 32)
        {
            fireBullet();   
        }
    }

    public function myOnRelease(event:KeyboardEvent):void
    {

        if(event.keyCode == Keyboard.LEFT || event.keyCode == Keyboard.RIGHT)
        {
            xAcceleration  = 0;
        }
        else if(event.keyCode == Keyboard.UP || event.keyCode == Keyboard.DOWN)
        {
            yAcceleration  = 0;
        }

    }       

    public function fireBullet() {
        if (shotCooldown <=0 )
        {
            shotCooldown=MAX_COOLDOWN;
            var b = new Bullet();
            var b2= new Bullet();
            b.x = this.x +20;
            b.y = this.y ;
            b2.x= this.x -20;
            b2.y= this.y ;
            MovieClip(parent).bullets.push(b);
            MovieClip(parent).bullets.push(b2);
            trace(bullets.length);
            parent.addChild(b);
            parent.addChild(b2);
        }
    }

}
package com.ply
{
导入flash.display.MovieClip;
导入flash.display.*;
导入flash.events.Event;
导入flash.events.KeyboardEvent;
导入flash.ui.Keyboard;
导入com.peluru.Bullet;
公共类直升机扩展MovieClip
{
冷却时间:int;
const MAX_冷却时间=10;
//背景
公共变量X加速度:数值=0;
公共变量Y加速度:数值=0;
私有变量xSpeed:Number=0;
私有变量ySpeed:Number=0;
private-var-up:Boolean=false;
private-var-down:Boolean=false;
私有变量left:Boolean=false;
private-var-right:Boolean=false;
公共职能部门
{
shotcollodown=最大冷却时间;
项目符号=新数组();
addEventListener(Event.ENTER_FRAME,update);
addEventListener(Event.ADDED_至_阶段,OnAddedStatage);
init();
}
AddedStatage上的公共函数(事件:事件):无效
{
移除EventListener(Event.ADDED_至_阶段,OnAddedStatage);
stage.addEventListener(KeyboardEvent.KEY_DOWN,myOnPress);
stage.addEventListener(KeyboardEvent.KEY\u UP,myOnRelease);
init();
}
私有函数init():void
{
addEventListener(Event.ENTER_FRAME,RunHeli);
}
私有函数RunHeli(事件:事件):void
{
xSpeed+=xAcceleration;//通过加速度增加速度
ySpeed+=YAAcceleration;//通过加速度增加速度
xSpeed*=0.95;//施加摩擦力
ySpeed*=0.95;//因此速度会随着时间的推移而降低
if(Math.abs(xSpeed)<0.02)//如果速度真的很低
{
xSpeed=0;//将其设置为0
//否则我会变得很小,但永远不会真正的0
}
if(Math.abs(ySpeed)<0.02)//y速度相同
{
y速度=0;
}
xSpeed=Math.max(Math.min(xSpeed,10),-10);//不要让速度变大到10
ySpeed=Math.max(Math.min(ySpeed,10),-10);//不要让它小于-10
this.x+=xSpeed;//按速度增加位置
this.y+=ySpeed;//idem
}
公共功能更新(e:事件){
冷却时间--;
}
/**
*键盘处理程序
*/
公共功能myOnPress(事件:KeyboardEvent):无效
{
if(event.keyCode==Keyboard.LEFT)
{
X加速度=-1;
}
else if(event.keyCode==Keyboard.RIGHT)
{
X加速度=1;
}
else if(event.keyCode==Keyboard.UP)
{
Y加速度=-1;
}
else if(event.keyCode==Keyboard.DOWN)
{
加速度=1;
}
else if(event.keyCode==32)
{
火弹();
}
}
公共函数myOnRelease(事件:KeyboardEvent):无效
{
if(event.keyCode==Keyboard.LEFT | | event.keyCode==Keyboard.RIGHT)
{
X加速度=0;
}
else if(event.keyCode==Keyboard.UP | | event.keyCode==Keyboard.DOWN)
{
加速度=0;
}
}       
公共功能fireBullet(){
如果(shotcollodown=0;bulletNum--){
对于(var airplaneNum:int=feeds.length-1;airplaneNum>=0;airplaneNum--){
if(子弹[bulletNum].hitTestObject(敌人[airplaneNum])){
敌人[Airplaneum].planeHit();
项目符号[bulletNum].deleteBullet();
trace(“kena”);
//shotsHit++;
//showGameScore();
打破
}
}
}
//如果((shotsLeft==0)和(&(bullets.length==0)){
//结束游戏();
//}
}
公共功能返回(evt:事件):无效
{//背景地
如果(甜点2.y>=0和甜点.y>=720)
{
甜点.y=甜点2.y-1240;
}
else if(甜点.y>=0和甜点2.y>=720)
{
甜点2.y=甜点.y-1240;
}
其他的
{
甜点.y=甜点.y+5;
甜品2.y=甜品2.y+5;
}
//背景云
如果(Clouds2.y>=0&&Clouds.y>=720)
{
Clouds.y=Clouds2.y-2480;
}
else if(Clouds.y>=0&&Clouds2.y>=720)
{
Clouds2.y=Clouds.y-2480;
}
其他的
{
云.y=云.y+10;
Clouds2.y=Clouds2.y+10;
}
}
公共函数startPlayer():void{
player=新直升机();
player.x=stage.stageWidth/2;
player.y=stage.stageHeight/2;
//将播放器添加到显示列表
舞台。儿童(玩家);
gameState=状态\游戏\游戏;
}
公共函数playGame():无效{
gameLoop();
//txtScore.text='Score:'+Score;
}
函数加法器(事件:事件){
如果(enemyTimepackage  
{
import com.ply.Heli;
import com.peluru.Bullet;
import com.musuh.Airplane2;

import flash.display.Sprite;
import flash.display.Stage;
import flash.display.MovieClip;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.display.*;
import flash.events.*;
import flash.utils.*;

public class Main extends MovieClip
{
    public static const STATE_INIT:int = 10;
    public static const STATE_START_PLAYER:int = 20;
    public static const STATE_PLAY_GAME:int = 30;
    public static const STATE_REMOVE_PLAYER:int = 40;
    public static const STATE_END_GAME:int = 50;        
    public var gameState:int = 0;
    public var player:Heli;
    public var enemy:Airplane2;
    //public var bulletholder:MovieClip = new MovieClip();

    //================================================
    public var cTime:int = 1;
    //the time it has to reach in order to be allowed to shoot (in frames)
    public var cLimit:int = 10;
    //whether or not the user is allowed to shoot
    public var shootAllow:Boolean = true;
    //how much time before another enemy is made
    public var enemyTime:int = 0;
    //how much time needed to make an enemy
    //it should be more than the shooting rate
    //or else killing all of the enemies would
    //be impossible :O
    public var enemyLimit:int = 64;
    //the player's score
    public var score:int = 0;
    public var gameOver:Boolean = false;
    public var bulletContainer:MovieClip = new MovieClip();
    //================================================
    private var nextPlane:Timer;
    public var enemies:Array;
    public var bullets:Array;

    public function Main() 
    {
        gameState = STATE_INIT;
        gameLoop();
    }


    public function gameLoop(): void {
        switch(gameState) {
            case STATE_INIT :
                initGame();
                break
            case STATE_START_PLAYER:
                startPlayer();
                break;  
            case STATE_PLAY_GAME:
                 playGame();
                break;
            case STATE_REMOVE_PLAYER:
                //removePlayer();
                break;      
            case STATE_END_GAME:                    
                break;  

        }

    }       

    public function initGame() :void {
        enemies = new Array();
        bullets = ne Array();

        setNextPlane();

        gameState = STATE_START_PLAYER;
        gameLoop();
        //stage.addEventListener(Event.ENTER_FRAME, AddEnemy);
        stage.addEventListener(Event.ENTER_FRAME, back);
        stage.addEventListener(Event.ENTER_FRAME,checkForHits);
    }

    public function setNextPlane() {
        nextPlane = new Timer(1000+Math.random()*1000,1);
        nextPlane.addEventListener(TimerEvent.TIMER_COMPLETE,newPlane);
        nextPlane.start();
    }


    public function newPlane(event:TimerEvent) {
        // random side, speed and altitude

        // create plane
        var enemy:Airplane2 = new Airplane2();
        enemy.y = -1 * enemy.height;
        //making the enemy's x coordinates random
        //the "int" function will act the same as Math.floor but a bit faster
        enemy.x = Math.floor(Math.random()*(stage.stageWidth - enemy.width));
        //then add the enemy to stage
        addChild(enemy);
        enemies.push(enemy);

        // set time for next plane
        setNextPlane();
    }

    public function removePlane(plane:Airplane2) {
        for(var i in enemies) {
            if (enemies[i] == plane) {
                enemies.splice(i,1);
                break;
            }
        }
    }

    // take a bullet from the array
    public function removeBullet(bullet:Bullet) {
        for(var i in bullets) {
            if (bullets[i] == bullet) {
                bullets.splice(i,1);
                break;
            }
        }
    }

    public function checkForHits(event:Event) {
        for(var bulletNum:int=bullets.length-1;bulletNum>=0;bulletNum--){ 
            for (var airplaneNum:int=enemies.length-1;airplaneNum>=0;airplaneNum--) {
                if (bullets[bulletNum].hitTestObject(enemies[airplaneNum])) {
                    enemies[airplaneNum].planeHit();
                    bullets[bulletNum].deleteBullet();
                    trace("kena");
                    //shotsHit++;
                    //showGameScore();
                    break;
                }
            }
        }

        //if ((shotsLeft == 0) && (bullets.length == 0)) {
        //  endGame();
        //}
    }


    public function back( evt:Event ):void
    {   // Backgroud Land
        if (Dessert2.y >= 0 && Dessert.y >= 720)
        {
            Dessert.y = Dessert2.y - 1240 ;
        }
        else if (Dessert.y >= 0 && Dessert2.y >= 720)
        {
            Dessert2.y = Dessert.y - 1240 ;
        }
        else 
        {
        Dessert.y = Dessert.y +5 ;
        Dessert2.y = Dessert2.y +5 ;
        }
        // Background Clouds
        if (Clouds2.y >= 0 && Clouds.y >= 720)
        {
            Clouds.y = Clouds2.y - 2480 ;
        }
        else if (Clouds.y >= 0 && Clouds2.y >= 720)
        {
            Clouds2.y = Clouds.y - 2480 ;
        }
        else 
        {
        Clouds.y = Clouds.y +10 ;
        Clouds2.y = Clouds2.y +10 ;
        }
    }

    public function startPlayer() : void { 
        player=new Heli();
        player.x = stage.stageWidth / 2;
        player.y = stage.stageHeight / 2;
        // add Player to display list
        stage.addChild(player);
        gameState = STATE_PLAY_GAME;

    }

    public function playGame():void {

        gameLoop();

        //txtScore.text = 'Score: '+score;


    }

    function AddEnemy(event:Event){
    if(enemyTime < enemyLimit){
        enemyTime ++;
    }   else {
        //defining a variable which will hold the new enemy
        enemy =new Airplane2();
        //making the enemy offstage when it is created
        enemy.y = -1 * enemy.height;
        //making the enemy's x coordinates random
        //the "int" function will act the same as Math.floor but a bit faster
        enemy.x = Math.floor(Math.random()*(stage.stageWidth - enemy.width));
        //then add the enemy to stage
        addChild(enemy);
        //and reset the enemyTime
        enemyTime = 0;

     }



        if(cTime <= cLimit){
            cTime ++;
        } else {
        //if it has, then allow the user to shoot
        shootAllow = true;
        //and reset cTime
        cTime = 1;
        }

    }

}
public function startPlayer() : void { 
    player=new Heli();
    player.x = stage.stageWidth / 2;
    player.y = stage.stageHeight / 2;
    // add Player to display list
    this.addChild(player); // <-- this, not stage
    gameState = STATE_PLAY_GAME;

}
MovieClip(parent).bullets.push(b);
MovieClip(parent).bullets.push(b2);
MovieClip(root).bullets.push(b);
MovieClip(root).bullets.push(b2);