Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Error Message When Using a Class Files to Control Navigation

Engaged ,
Feb 10, 2013 Feb 10, 2013

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");

        }

    }

}

TOPICS
ActionScript
761
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Feb 10, 2013 Feb 10, 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");

        }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 11, 2013 Feb 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 11, 2013 Feb 11, 2013

When I changed the code I got error (1046: Type was not found or was not a compile-time constant: MouseEvent).

package

{

    import flash.display.SimpleButton;

    public class Navigation extends SimpleButton

    {

        public function Navigation()

        {

            this.addEventListener(MouseEvent.MOUSE_DOWN, goNavigation);

        }

        private function goNavigation(event:MouseEvent):void

        {

            root.gotoAndPlay(1,"Main");

        }

    }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Feb 11, 2013 Feb 11, 2013

...

import flash.display.SimpleButton;

import flash.events.MouseEvent

...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 12, 2013 Feb 12, 2013
LATEST

Note that if you look at the screen while you are typing or press Ctrl-Space while you are typing, you can take advantage of code completion, which will do your imports for you.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines