Monday, July 2, 2012

[Action Script] Button to MovieClip July,2012

Hi there,

The 'Home' screen of the game I'm working on has 3 links. Play / Credits / How to Play.

The Play button does work, but the Credits and How to Play buttons don't. I can't figure out what it is I'm doing wrong. I think it's going wrong in the 'Doument Class' file.

Please, can someone help me? I'm stuck.

Code 'Home Screen':


public function CreditsScreen()
{
ButtonCredits.addEventListener( MouseEvent.CLICK, onClickCredits );
}

public function onClickCredits( event:MouseEvent ):void
{
dispatchEvent( new NavigationEvent( NavigationEvent.CREDITS ) );
}

public function HowToPlayScreen()
{
ButtonHowToPlay.addEventListener( MouseEvent.CLICK, onClickHowToPlay );
}

public function onClickHowToPlay( event:MouseEvent ):void
{
dispatchEvent( new NavigationEvent( NavigationEvent.HOWTOPLAY ) );
}
}
}

Code 'Navigation Event':


package
{
import flash.events.Event;
public class NavigationEvent extends Event
{
public static const REPLAY:String = "replay";
public static const PLAY:String = "play";
public static const HOME:String = "home";
public static const CREDITS:String = "credits";
public static const HOWTOPLAY:String = "howtoplay";

public function NavigationEvent( type:String )
{
super( type );
}
}
}

Code 'Document Class':

package
{
import flash.display.MovieClip;
public class DocumentClass extends MovieClip
{
public var homeScreen:HomeScreen;
public var playScreen: DoodleSpaceInvaders;
public var gameOverScreen:GameOverScreen;
public var creditsScreen:CreditsScreen;
public var howToPlayScreen:HowToPlayScreen;

public function showCreditsScreen():void
{
creditsScreen = new CreditsScreen();
creditsScreen.addEventListener( NavigationEvent.CREDITS, onRequestCredits );
creditsScreen.x = 0;
creditsScreen.y = 0;
addChild( creditsScreen );
}

public function onRequestCredits( navigationEvent:NavigationEvent ):void
{
creditsScreen = new CreditsScreen();
creditsScreen.addEventListener( NavigationEvent.CREDITS, onRequestCredits );
creditsScreen.x = 0;
creditsScreen.y = 0;
addChild( creditsScreen );

homeScreen = null;
}

public function showHowToPlayScreen():void
{
howToPlayScreen = new HowToPlayScreen();
howToPlayScreen.addEventListener( NavigationEvent.HOWTOPLAY, onRequestHowToPlay );
howToPlayScreen.x = 0;
howToPlayScreen.y = 0;
addChild( howToPlayScreen );
}

public function onRequestHowToPlay( navigationEvent:NavigationEvent ):void
{
howToPlayScreen = new HowToPlayScreen();
howToPlayScreen.addEventListener( NavigationEvent.HOWTOPLAY, onRequestHowToPlay );
howToPlayScreen.x = 0;
howToPlayScreen.y = 0;
addChild( howToPlayScreen );

homeScreen = null;
}
}
}
Button to MovieClip

Related Post



0 comments: