Jacques
Jacques

Reputation: 61

1046: Type was not found or was not a compile-time constant: startButton

I was doing a tutorial and got this error.

Line 3 1046: Type was not found or was not a compile-time constant: startButton.

I did some research and I found someone who had excatly the same problem. He was helped in the comment section. the creator of the tutorial told him the following:

"Have you turned “auto-declare stage instances” on, as in the start of Part 1? Also, is your startButton inside the MenuScreen clip, and is the MenuScreen exported for ActionScript?"

Now i think i haven't auto-declared stage instances. (the other things are done, I did a double check) But it's a bit vague to me what it means, could you possible tell me how to do “auto-declare stage instances” after already having it all coded.

the link to tutorial: http://gamedev.michaeljameswilliams.com/2008/10/12/avoider-game-tutorial-4/comment-page-5/#comments

package 
{
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.events.MouseEvent;

public class MenuScreen extends MovieClip 
{

    public function MenuScreen()
    {

        startButton.addEventListener( MouseEvent.CLICK, onClickStart );
    }

    public function onClickStart( event:MouseEvent ):void
    {
        dispatchEvent( new NavigationEvent( NavigationEvent.START ) );
    }
}
}

Upvotes: 0

Views: 1731

Answers (1)

fsbmain
fsbmain

Reputation: 5267

add

public var startButton:SimpleButton;

or

public var startButton:MovieClip;

to the class MenuScreen depending on type of startButton on the scene. Be sure that you gave the name startButton to the button instance and don't forget to assign class MenuScreen to the component that holds the startButton.

Upvotes: 1

Related Questions