错误1180调用可能未定义的方法Bullet

时间:2014-07-16 13:52:20

标签: actionscript-3 flash-cs5

我在这里有一个问题,我已经尽力弄明白为什么我在第325行遇到这个错误。这是整个脚本。我正在使用Flash CS5.5。谢谢你的帮助,因为我完全陷入困境。我更改了movieClips的名称,但仍然存在错误。再次感谢。

import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.filters.BlurFilter;
import flash.utils.getTimer;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.system.fscommand;
import flash.text.TextFormat;
import flash.text.TextField;
import flash.display.Graphics;
import flash.display.MovieClip;
import flash.display.SimpleButton;

var loader:Loader = new Loader();
var file:URLRequest = new URLRequest("vermin-ator.swf");
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteLoad);

loader.load(file);

function onCompleteLoad (loadEvent:Event):void
{
    addChild(loadEvent.currentTarget.content);
}





        // player settings      
         var _rotateSpeedMax:Number = 20;
        //private var _gravity:Number = .68;

        // projectile gun settings
         var _bulletSpeed:Number = 8;       
         var _maxDistance:Number = 300;
         var _reloadSpeed:Number = 250; //milliseconds
         var _barrelLength:Number = 20;
         var _bulletSpread:Number = 5;
         var score:int = 0;

        // gun stuff - do not edit
         var _isLoaded:Boolean = true;      
         var _isFiring:Boolean = false;
         var _endX:Number;
         var _endY:Number;
         var _startX:Number;
         var _startY:Number;
         var _reloadTimer:Timer;
         var _bullets:Array = [];

        // array that holds walls
         //var _solidObjects:Array = [];
         //array for rifle sounds
         var mySoundArray:Array = [];
         var mySoundRandom:Number;

         //game scorings
         //var myFormat:TextFormat = new TextFormat();
        // myFormat.size = 20;
         //var gameScoreField:TextField;

         //var gameScore:int;
        // gameScore = 0;
        // var myText_txt:TextField = new TextField();

        // global vars
         var player:MovieClip;
         //var _player2:MovieClip;
         //var _player3:MovieClip;
         var _dx:Number;
         var _dy:Number;
         var _pcos:Number;
         var _psin:Number;
         var _trueRotation:Number;
         var count:Number;

         var dougie:MovieClip;
         var murphy:MovieClip;
         var dougieTalk:MovieClip;
         var murphyTalk:MovieClip;
         var murphyScream:MovieClip;
         var newRabbit:MovieClip;
         var tempBullet:MovieClip;
         var bullet_mc:MovieClip;

        //how much time before another rabbit is made
        var rabbitTime:int = 0;
        //how much time is needed to make a rabbit
        var rabbitLimit:int = 16;
        //this movieclip holds the bullets
        //var bulletContainer:MovieClip = new MovieClip();
        //addChild(bulletContainer)

        var soundOn:Boolean = true;
        //var myTransform:SoundTransform;

    //variable for rifle sound
    var rifle1Sound:Sound = new rifle1sound();
    //variable for rifle sound
    var rifle2Sound:Sound = new rifle2sound();
    //variable for rifle sound
    var rifle3Sound:Sound = new rifle3sound();
    //variable for rifle sound
    var rifle4Sound:Sound = new rifle4sound();

    //variable for man laughing
    //var manLaughSound:Sound = new manlaughsound();
    //variable for man laughing
    //var manPleasedSound:Sound = new manpleasedsound();
    //varible for background sound
    var bckgroundSound:Sound = new bckgroundsound();
    //varible for rabbit shot sound
    //var rabbitSound:Sound = new rabbitsound();
    //variable for button sound
    var BtnSound:Sound = new buttonSound();




    //make screen for Stop invisible
    var stopScreen:MovieClip;
    //make screen for Credits visible
    var creditScreen:MovieClip;
    //make screen for Rules visible
    var rulesScreen:MovieClip;

    murphyTalk.visible = true;
    dougieTalk.visible = true;
    dougie.visible = true;
    murphy.visible = true;
    murphyScream.visible = true;
    creditScreen.visible = true;
    rulesScreen.visible = true;
    stopScreen.visible = false;


    //enable hand cursors on mouse over over buttons
    var movieClip_8:MovieClip;
    var movieClip_9:MovieClip;
    var movieClip_10:MovieClip;
    var movieClip_11:MovieClip;
    var newrabbit:MovieClip;
    var closeGame:MovieClip;

    //listener and function for how to play button
movieClip_10.addEventListener(MouseEvent.MOUSE_DOWN, helpScreen);
function helpScreen(evt:MouseEvent):void {
    rulesScreen.visible=true;
}

        //listener and function for how to play button
movieClip_9.addEventListener(MouseEvent.MOUSE_DOWN, ahelpScreen);
function ahelpScreen(evt:MouseEvent):void {
    creditScreen.visible=true;
}
    //Add event listeners for all 3 Over, Out and Down
    movieClip_8.addEventListener(MouseEvent.MOUSE_OVER, mOver);
    function mOver(e:MouseEvent):void { 
    murphyTalk.visible = false;
    dougieTalk.visible = false;
    dougie.visible = false;
    murphy.visible = false;
    murphyScream.visible= true;

    }
    movieClip_8.addEventListener(MouseEvent.MOUSE_OUT, mOut);

//Mouse methods
function mOut(e:MouseEvent):void { 
    murphyScream.visible= false;
    removeChild(murphyTalk);
    removeChild(dougieTalk);
    removeChild(dougie);
    removeChild(murphy);

     //Remove all listeners
movieClip_8.removeEventListener(MouseEvent.MOUSE_OVER, mOver);
movieClip_8.removeEventListener(MouseEvent.MOUSE_OUT, mOut);



    }


        /**
         * Constructor
         */
        //public function Main() 

        /*recurring event listener for updates
addEventListener(Event.ENTER_FRAME,showGameScore);
    function showGameScore() {
    gameScoreField.text = "Game: "+String(gameScore);
    addChild(gameScoreField); */
movieClip_8.addEventListener(MouseEvent.MOUSE_DOWN, mDown); 
function mDown(e:MouseEvent):void { 

    createPlayer();

            // add listeners
            stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
            stage.addEventListener(MouseEvent.MOUSE_DOWN, `enter code here`onMouseDownHandler);
            stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUpHandler);

            // add movieclips to solidObjects array
            // will test for collisions with bullets
            //
            // *** movieclips are located on stage in the fla
            //_solidObjects = [rabbit01, rabbit02, rabbit03, rabbit04];
            //adding enemies to stage
    if(rabbitTime < rabbitLimit){
    //if time hasn't reached the limit, then just increment
    rabbitTime ++;
        } else {
    //defining a variable which will hold the new enemy
    //var newRabbit:MovieClip = new Rabbit();
    //making the enemy offstage when it is created
    newrabbit.s = -1 * newrabbit.width;
    //making the enemy's x coordinates random
    //the "int" function will act the same as Math.floor but a bit faster
    newrabbit.x = int(Math.random()*(stage.stageWidth - newrabbit.width));
    //then add the enemy to stage
    addChild(newrabbit);
    //and reset the enemyTime
    rabbitTime = 0;
}


        //////////////////////////////////////
        // Player & Weapon Methods
        //////////////////////////////////////

        /**
         * Creates player
         * Uses "Player" movieclip linked in library
         */
        function createPlayer():void
        {
            // attach player movieclip from library
            player = new Player();

            // position player in center
            player.x = stage.stageWidth / 2;
            //_player.y = stage.stageHeight / 2;

            // add to display list
            stage.addChild(player);
        }



        /**
         * Reload timer
         * @param   e   Takes TimerEvent
         */
        function reloadTimerHandler(e:TimerEvent):void 
        {
            // stop timer
            e.target.stop();

            // clear timer var
            _reloadTimer = null;

            reloadWeapon();
        }


        /**
         * Fire weapon
         */
         function fire():void
        {
            // check if firing
            if (!_isFiring) return;

            // check if reloaded
            if (!_isLoaded) return;

            // create bullet
            createBullet();

            // start reload timer
            _reloadTimer = new Timer(_reloadSpeed);
            _reloadTimer.addEventListener(TimerEvent.TIMER, `enter code here`reloadTimerHandler);
            _reloadTimer.start();

            // set reload flag to false
            _isLoaded = false;
        }

        /**
         * Creates a bullet movieclip and sets it's properties
         */
        function createBullet():void
        {
            // precalculate the cos & sine
            _pcos = Math.cos(player.rotation * Math.PI / 180);
            _psin = Math.sin(player.rotation * Math.PI / 180);

            // start X & Y
            // calculate the tip of the barrel
            _startX = player.x - _barrelLength * _pcos;
            _startY = player.y - _barrelLength * _psin;

            // end X & Y
            // calculate where the bullet needs to go
            // aim 50 pixels in front of the gun
            _endX = player.x - 50 * _pcos + Math.random() * _bulletSpread - `enter code here`_bulletSpread * .5;
            _endY = player.y - 50 * _psin + Math.random() * _bulletSpread - `enter code here`_bulletSpread * .5;

            // attach bullet from library
            var tempBullets:MovieClip = new Bullet();

            // calculate velocity
            tempBullets.vx = (_endX - _startX) / _bulletSpeed;
            tempBullets.vy = (_endY - _startY) / _bulletSpeed;

            // set position
            tempBullets.x = _startX;
            tempBullets.y = _startY;

            // save starting location
            tempBullets.startX = _startX;
            tempBullets.startY = _startY;

            // set maximum allowed travel distance
            tempBullets.maxDistance = _maxDistance;

            // add bullet to bullets array
            _bullets.push(tempBullets);

            // add to display list
            stage.addChild(tempBullets);
        }

        /**
         * Updates bullets
         */
        function updateBullets():void
        {
            var i:int;
            var tempBullets:MovieClip;

            // loop thru _bullets array
            for (i = 0; i < _bullets.length; i++)
            {
                // save a reference to current bullet
                tempBullets = _bullets[i];

                // check if gravity is enabled
                //if (gravityCheckbox.selected)
                //{
                    // add gravity to Y velocity
                    //tempBullet.vy += _gravity;
                }

                // update bullet position
                tempBullets.x += tempBullets.vx;
                tempBullets.y += tempBullets.vy;

                // check if bullet went too far
                if (getDistance(tempBullets.startX - tempBullets.x, `enter code here`tempBullets.startY - tempBullets.y) > tempBullets.maxDistance + `enter code here`_barrelLength)
                {
                    destroyBullet(tempBullets);
                }

                // check for collision with walls
                if (checkCollisions(tempBullets.x, tempBullets.y))
                {
                    destroyBullet(tempBullets);
                }

        }

        /**
         * Destroys bullet
         * @param   bullet  Takes bullet movieclip
         */
         function destroyBullet(bullet_mc:MovieClip):void
        {
            var i:int;
            var tempBullets:MovieClip;

            // loop thru _bullets array
            for (i = 0; i < _bullets.length; i++)
            {
                // save a reference to current bullet
                tempBullets = _bullets[i];

                // if found bullet in array
                if (tempBullets == bullet_mc)
                {
                    // remove from array
                    _bullets.splice(i, 1);

                    // remove from display list
                    _bullets.removeChild(bullet_mc);

                    // stop loop
                    return;
                }
            }
        }

        /**
         * Reload weapon
         */
        function reloadWeapon():void
        {
            _isLoaded = true;
        }

        /**
         * Checks for collisions between points and objects in _solidObjects
         * @return  Collision boolean
         */
         function checkCollisions(testX:Number, testY:Number):Boolean
        {
            //var i:int;
            var newrabbit:MovieClip;

            // loop thru _solidObjects array
            //for (i = 0; i < _solidObjects.length; i++)
            {
                // save a reference to current object
                //newRabbit = _solidObjects[i];

                // do a hit test
                if (newrabbit.hitTestPoint(testX, testY, true))
                {

                    return true;


                    // stop loop
                    //break;
                }
            }
            return false;
        }


        /**checking if Rabbits is touching any bullets

        for(var i:int = 0;i<_root.bulletContainer.numChildren;i++){
    //numChildren is the amount of movieclips within the bulletContainer.

    //we define a variable that will be the bullet that we are currently
    //hit testing.
    var bulletTarget:MovieClip = _root.bulletContainer.getChildAt(i);

    //now we hit test
    if(hitTestObject(bulletTarget)){
        //remove this from the stage if it touches a bullet
        removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
        _root.removeChild(this);
        //also remove the bullet and its listeners
        _root.bulletContainer.removeChild(bulletTarget);
        bulletTarget.removeListeners();
    }
}*/



        /**
         * Calculate player rotation 
         */
        function updateRotation():void
        {
            // calculate rotation based on mouse X & Y
            _dx = player.x - stage.mouseX;
            _dy = player.y - stage.mouseY;

            // which way to rotate
            var rotateTo:Number = getDegrees(getRadians(_dx, _dy)); 

            // keep rotation positive, between 0 and 360 degrees
            if (rotateTo > player.rotation + 90) rotateTo -= 180;
            if (rotateTo < player.rotation - 90) rotateTo += 180;

            // ease rotation
            _trueRotation = (rotateTo - player.rotation) / _rotateSpeedMax;

            // update rotation
            player.rotation += _trueRotation;           
        }

        //////////////////////////////////////
        // Event Handlers
        //////////////////////////////////////

        /**
         * Enter Frame handler
         * @param   event   Uses Event
         */
        function enterFrameHandler(event:Event):void
        {
            updateRotation();
            updateBullets();
            fire();


        }
        /**
         * Mouse Up handler
         * @param   e   Uses MouseEvent
         */
        function onMouseUpHandler(event:MouseEvent):void 
        {
            _isFiring = false;
            //make bubble for Run Scream invisible
            murphyScream.visible = false;
        }

        /**
         * Mouse Down handler
         * @param   e   Uses MouseEvent
         */
         function onMouseDownHandler(event:MouseEvent):void 
        {
            _isFiring = true;

            //play random rifle sound from an array
            var mySoundArray:Array = new Array(rifle1sound, rifle2sound, `enter code here`rifle3sound, rifle4sound);
            `enter code here`mySoundArray[Math.floor(Math.random()*mySoundArray.length)].play();
        }


        //////////////////////////////////////
        // Utilities
        //////////////////////////////////////

        /**
         * Get distance
         * @param   delta_x
         * @param   delta_y
         * @return
         */
        function getDistance(delta_x:Number, delta_y:Number):Number
        {
            return Math.sqrt((delta_x*delta_x)+(delta_y*delta_y));
        }

        /**
         * Get radians
         * @param   delta_x
         * @param   delta_y
         * @return
         */
         function getRadians(delta_x:Number, delta_y:Number):Number
        {
            var r:Number = Math.atan2(delta_y, delta_x);

            if (delta_y < 0)
            {
                r += (2 * Math.PI);
            }
            return r;
        }

        /**
         * Get degrees
         * @param   radians Takes radians
         * @return  Returns degrees
         */
        function getDegrees(radians:Number):Number
        {
            return Math.floor(radians/(Math.PI/180));


    }

    movieClip_8.removeEventListener(MouseEvent.MOUSE_DOWN, mDown);



}

        //listener and function for how to play button
    movieClip_11.addEventListener(MouseEvent.MOUSE_DOWN, bhelpScreen);
    function bhelpScreen(evt:MouseEvent):void {
    stopScreen.visible=true;


        }
closeGame.addEventListener(MouseEvent.MOUSE_DOWN, closeApp);

function closeApp(event:MouseEvent):void {
    fscommand("quit");

}

1 个答案:

答案 0 :(得分:0)

检查Bullet是否也是库中的类名。