Skip to main content
Mr. Baker the Shoe Maker
Inspiring
February 11, 2013
Question

Error Message When Using a Class Files to Control Navigation

  • February 11, 2013
  • 1 reply
  • 830 views

This is my first attempt at using a class file in a flash project. My intent is to keep all of my navigation elements in class file called "Navigation".  However, I keep getting an error message when I publish.

I am using a button to go back to the main screen and I gave that button the instance name of "bnt_home". I have also linked that button in the library to the class "Navigation".

Here is the code:

package

{

    import flash.display.SimpleButton;

    public class Navigation extends SimpleButton

    {

        public function Navigation()

        {

            bnt_home.addEventListener(MouseEvent.MOUSE_DOWN, goNavigation);

        }

        private function goNavigation(event:MouseEvent):void

        {

            gotoAndPlay(1,"Main");

        }

    }

}

This topic has been closed for replies.

1 reply

Inspiring
February 11, 2013

2 problems:

public function Navigation()

        {

            bnt_home.addEventListener(MouseEvent.MOUSE_DOWN, goNavigation);

          // should be : this.addEventListener(MouseEvent.CLICK, goNavigation)

        }

        private function goNavigation(event:MouseEvent):void

        {

            gotoAndPlay(1,"Main");

           //should be : this.parent.gotoAndPlay(1,"Main");

          //or root.gotoAndPlay(1,"Main");

        }

Amy Blankenship
Legend
February 11, 2013

Better still, the Class shouldn't know or try to know anything about what its environment is, and the parent MC should listen for a custom event that the Navigation class dispatches based on a click on itself or the child button.

Note that it's easier for people to see if your Class is set up properly if you uncheck "declare stage instances automatically" and you then declare the instances in the Class. It also helps with auto code-completion, especially if you're using an external IDE like Flash Builder or FlashDevelop to help you code more efficiently.