samedi 10 décembre 2016

Keeps saying "a term is undefined" when it is actually defined?

So, from what I've read and understood, the 1010 error, where it says "a term is undefined and has no properties" means that some variable has not been declared or it has been declared but doesn't have any properties to begin with. Is that correct? If so, then why does it give me the error at "if (_root.removeProjectiles == true)" from this class code:

package
{
    import flash.display.MovieClip;
    import flash.events.*;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    public class weapon1projectileCode extends MovieClip
    {
        private var _root:Object;
        private var speed:int = 10;
        public function weapon1projectileCode()
        {
            addEventListener(Event.ADDED, beginClass);
            addEventListener(Event.ENTER_FRAME, entFrame);
            playSound();
        }
        private function beginClass(event:Event):void
        {
            _root = MovieClip(root);
            this.scaleX = .25;
            this.scaleY = .2;
        }
        private function playSound():void
        {
            var sndFire:weapon1projectile_sound;
            var sndFireChannel: SoundChannel;
            sndFire = new weapon1projectile_sound();
            sndFireChannel = sndFire.play();
        }
        private function entFrame(event:Event):void
        {
            if (_root.gamePaused == false)
            {
                x += speed;
                if(this.x > (stage.width+ this.width))
                {
                    removeEventListener(Event.ENTER_FRAME, entFrame);
                    _root.projectilePlayerContainer.removeChild(this);
                }
            }
            if (_root.removeProjectiles == true)
            {
                removeEventListener(Event.ENTER_FRAME, entFrame);
                _root.projectilePlayerContainer.removeChild(this);
            }
        }
        public function removeListeners():void
        {
            removeEventListener(Event.ENTER_FRAME, entFrame);
        }
    }
}

When it has been declared in the main code as "". And besides, the "if (_root.gamePaused == false)" in the same exact class code works, even though it's essentially the same structure and the same kind of code is in another class and it works, but this doesn't. Why? What is going on here exactly?

I should also mention that the error appears in output log whenever "removeProjectiles = true" and in this case, it's at the end of the level when an upgrade menu shows up. Let me know if you would like to see that part of the code too.

Aucun commentaire:

Enregistrer un commentaire