Junk Byte Code for Kicks

22Feb/120

Console command prompt addon demo

Finally got time to do a simple demo of "CommandPrompt" addon.

I used this addon for a utility AIR app at my work.
The app is a simple command line where you choose what you want to do and it does stuff according to your choices.

Here is a simple greetings demo:
(your selections do not get recorded :)
http://console.junkbyte.com/addons/commandprompt/

Source code:


package
{
	import com.junkbyte.console.Cc;
	import com.junkbyte.console.addons.commandprompt.CommandChoice;
	import com.junkbyte.console.addons.commandprompt.CommandPrompt;

	import flash.display.Sprite;

	[SWF(width = '640', height = '480', backgroundColor = '0xFFFFFF', frameRate = '30')]
	public class CommandPromptTest extends Sprite
	{
		public function CommandPromptTest()
		{
			Cc.startOnStage(this);
			Cc.width = 640;
			Cc.height = 480;
			Cc.commandLine = true;

			Cc.instance.panels.mainPanel.scalable = false; // Disable scaling
			Cc.instance.panels.mainPanel.moveable = false; // Disable moving

			Cc.clear();

			askHowAreYouFeeling();
		}

		private function askHowAreYouFeeling():void
		{
			var prompt:CommandPrompt = new CommandPrompt("Welcome to Command prompt demo...\nHow are you feeling today?");

			prompt.addCmdChoice(new CommandChoice("1", answeredFeelingGood, "Awesome"));
			prompt.addCmdChoice(new CommandChoice("2", answeredFeelingGood, "Good"));
			prompt.addCmdChoice(new CommandChoice("3", answeredFeelingBad, "Bad"));

			prompt.start();

			Cc.log("Type your answer key (1, 2 or 3) in command line below.");
		}

		private function answeredFeelingGood(input:String):void
		{
			Cc.info("Good to hear!");
			Cc.info("");
			askAboutFlashConsole();
		}

		private function answeredFeelingBad(input:String):void
		{
			askBadDayReason();
		}

		private function askBadDayReason():void
		{
			var prompt:CommandPrompt = new CommandPrompt("Bad? How come? Give me an explanation...");
			prompt.defaultCallback = answeredBadDayReason;
			prompt.start();
			Cc.log("(write anything in commandline)");
		}

		private function answeredBadDayReason(input:String):void
		{
			Cc.info("OK. What ever you say...");
			Cc.info("");

			askAboutFlashConsole();
		}

		private function askAboutFlashConsole():void
		{
			var prompt:CommandPrompt = new CommandPrompt("Do you like FlashConsole?");

			prompt.addCmdChoice(new CommandChoice("y", answeredLikeConsole, "Yes"));
			prompt.addCmdChoice(new CommandChoice("n", answeredDontLikeConsole, "No"));

			prompt.start();
		}

		private function answeredLikeConsole(input:String):void
		{
			var prompt:CommandPrompt = new CommandPrompt("Great!. Tell me what you like about it...");
			prompt.defaultCallback = answeredLikeConsoleQuestion;
			prompt.start();
			Cc.log("(write anything in commandline)");
		}

		private function answeredDontLikeConsole(input:String):void
		{
			var prompt:CommandPrompt = new CommandPrompt("Oh :( Tell me why you don't like it...");
			prompt.defaultCallback = answeredLikeConsoleQuestion;
			prompt.start();
			Cc.log("(write anything in commandline)");
		}

		private function answeredLikeConsoleQuestion(input:String):void
		{
			Cc.info("Sounds like an answer to me......");
			Cc.info("");

			var prompt:CommandPrompt = new CommandPrompt("Enter anything to restart this demo.");
			prompt.defaultCallback = answeredRestart;
			prompt.start();
		}

		private function answeredRestart(input:String):void
		{
			askHowAreYouFeeling();
		}
	}
}

Filed under: Console Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

No trackbacks yet.