0
votes

In some of the level MovieClips I have for my Flash game, there is a certain MovieClip that controls a custom-built camera that I've created. Both the camera and the MovieClip function correctly and smoothly. However, whenever a level is completed and removed from the game, I get an Error #1009 not recognizing the checkCameraZoom function. Also, this MovieClip is not added dynamically with code, but rather placed in the specified level MovieClips from the Library before run-time. Is there any possible way to fix this error?

ZoomOutArea Class:

package com.engine.assetHolders
{
    import com.engine.documentClass.*;
    import flash.display.*;
    import flash.events.*;

    public class ZoomOutArea extends MovieClip
    {
        public function ZoomOutArea():void
        {
            this.visible = false;
            this.addEventListener(Event.ADDED_TO_STAGE, initZoomOutArea);
            // constructor code
        }
        public function initZoomOutArea(event:Event):void
        {
            this.addEventListener(Event.ENTER_FRAME, checkCameraZoom);
        }
        public function checkCameraZoom(event:Event):void
        {
            if (Document.getInstance != null)
            {
                if (this.hitTestObject(MovieClip(parent.parent).player.playerHitArea))
                {
                    this.hitTestZoom(0.6);
                }
                if (! this.hitTestObject(MovieClip(parent.parent).player.playerHitArea))
                {
                    this.hitTestZoom(1);
                }
            }
        }
        public function hitTestZoom(zoomLevel):Number
        {
            MovieClip(parent.parent).cameraScale = zoomLevel;
            return zoomLevel;
        }
    }
}
1
You can first make a dummy function, and see if it recognizes that "dummy" function or not. That may add up some clarity to situation.Vishwas

1 Answers

1
votes

You register the class for ENTER_FRAME events when it's added to the stage, but you never unregister it. So that's why it keeps going even after it has been removed from the stage, and has no parent anymore. You could add another listener for Event.REMOVED_FROM_STAGE and then remove the checkCameraZoom listener:

    public function initZoomOutArea(event:Event):void
    {
        this.addEventListener(Event.ENTER_FRAME, checkCameraZoom);
        this.addEventListener(Event.REMOVED_FROM_STAGE, onRemoved);
    }

    private function onRemoved(event:Event):void
    {
         this.removeEventListener(Event.ENTER_FRAME, checkCameraZoom);
    }