Just Starting AS3 Not understanding Multi-class interaction
Hello, I have got a little game already and it works fine, but when i try and break it up into multi-classes It keeps giving me problems i have spend the last 2 days on this and still dont understand what i am doing wrong. Can you help me please. Here is my code.
---So what is going on is i just have a titlemenu class that i want to have everything i do in the title menu go on there when i try and add the event listener to the class it alwasy breaks saying its a null reference but i dont understand why that could be happneing.
package
{
import flash.display.MovieClip;
import com.natejc.input.KeyboardManager;
import com.natejc.input.KeyCode;
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.net.DynamicPropertyOutput;
import flash.text.TextField;
/**
* ...
* @7111211 ...
*/
public class TitleScreen extends MovieClip
{
public var btnStart :SimpleButton;
public function TitleScreen()
{
this.btnStart.addEventListener(MouseEvent.CLICK, btnStartClick);
}
/* ---------------------------------------------------------------------------------------- */
public function btnStartClick(ev:MouseEvent):void
{
gotoAndStop("Game");
}
}
}
****Main class *******
package
{
import com.natejc.input.KeyboardManager;
import com.natejc.input.KeyCode;
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.net.DynamicPropertyOutput;
import flash.text.TextField;
/**
* Drives the project.
*
* @7111211 Nate Chatellier
*/
public class Main extends MovieClip
{
public var tTitleScreen:TitleScreen=new TitleScreen();
public var gGameScreen:GameScreen=new GameScreen();
/* ---------------------------------------------------------------------------------------- */
/**
* Constructs the Main object.
*/
public function Main()
{
KeyboardManager.init(this.stage);
}
}
}
