I'm trying to create a intro screen
then a start screen
after the intro screen is done playing.
I thought the easiest way of doing this would be on scene 1 frame 1, I would create a
MovieClip
.
By the way this is a separate document file. So I gave it a document class name of mcStartGameScreen
and linked it to Flash Develop for actions.
Now the MovieClip
that is on frame 1, I gave an instance name of startMenu
then inside the startMenu
MovieClip there is a MovieClip that I wanted the buttonMode enabled to be true. I add this MovieClip which is called mcStart
on frame(65) inside my startMenu
.
Now in my Actions I have this:
public class mcStartGameScreen extends MovieClip
{
private var mcStart:MovieClip;
private var startMenu:MovieClip;
public function mcStartGameScreen()
{
startMenu.mcStart.buttonMode = true; //This is giving me the ERROR!
mcStart.addEventListener(MouseEvent.CLICK, startOnClick);
}
private function startOnClick(e:MouseEvent):void
{
dispatchEvent(new Event("START_GAME"));
}
public function hideScreen():void
{
this.visible = false;
}
public function showScreen():void
{
this.visible = true;
}
}
When I test the movie I get this
error: Cannot access a property or method of a null object reference.
Does anyone know what I am doing wrong?
If you already have a MovieClip
with instance name startMenu
placed on the stage, so no need for,
private var startMenu:MovieClip;
you remove this from your code.
And always have the stage instance first and then proceed.
So modify your constructor like so:
public function mcStartGameScreen()
{
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
private function onAddedToStage(e:Event):void
{
startMenu.mcStart.buttonMode = true; //Now this will not give the ERROR!
startMenu.mcStart.addEventListener(MouseEvent.CLICK, startOnClick);
}