Skip to content

Instantly share code, notes, and snippets.

@chyyran
Created February 12, 2013 23:24
Show Gist options
  • Save chyyran/4774456 to your computer and use it in GitHub Desktop.
Save chyyran/4774456 to your computer and use it in GitHub Desktop.
Snowflake UI Code
import Snowflake.UI.Test.Datastructures.Console;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.ui.Keyboard;
import mx.events.EffectEvent;
import flash.display.*;
[Bindable("effectDuration")]
private var effectDuration:Number = 250;
public var skinName:String="Snowflake_Default";
private var arrayLength:int;
public var selectedIndex:int = 0;
public var consoleArray:Array = new Array();
public var todayDate:Date = new Date();
public var dateCode:String = todayDate.month+"."+todayDate.date+"."+todayDate.fullYear+" "+todayDate.hours+":"+todayDate.minutes+":"+todayDate.seconds+"_"+todayDate.timezoneOffset;
private var inTransition:Boolean = false;
/**
* Gets the zero-relative length of a given array
* @param array Any array
* @return The length of the array
*/
private function getArrayLength(array:Array):int{
//We start counting at -1 because Array is zero relative
var count:int = -1;
for each (var object:Object in array){
count++
}
return count;
}
/**
* Appends "[Snowflake.UI.Skin]" to a string to log
* @param log String to log
*/
private function skinLog(log:String):void{
trace("[Snowflake.UI.Skin] " + log);
}
private function init(stage:Stage):void{
skinLog("SnowflakeUI Loaded at "+ dateCode);
skinLog("Skin name is "+skinName);
stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
skinLog("Display State = Fullscreen");
stage.addChild(new FPSCounter(10,10,0x000000,false,0x000000));
skinLog("FPS Counter initialized");
//stage.nativeWindow.maximize();
//skinLog("Display State = Maximized Window");
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDown);
skinLog("Keyboard event listener hooked");
insertConsole(new Console("assets/SNES.png","Super Nintendo Entertainment System","SNES",0));
insertConsole(new Console("assets/NES.png","Nintendo Entertainment System","NES",1));
insertConsole(new Console("assets/genesis.png","Sega Genesis","Genesis",2));
insertConsole(new Console("assets/MasterSystem.png","Sega Master System","SMS",3));
insertConsole(new Console("assets/n64.png","Nintendo 64","N64",4));
arrayLength = getArrayLength(consoleArray);
skinLog("Inserted "+String(arrayLength+1)+" consoles");
skinLog("Final ArrayLength is "+String(arrayLength));
updateConsole();
}
/**
* Inserts a console to the consoleArray
* @param console Console to insert
*/
private function insertConsole(console:Console):void{
consoleArray[console.indexPosition] = console;
skinLog("Inserted "+console.consoleName+" ("+console.shortName+")"+" with path "+console.imagePath+" to index "+String(console.indexPosition));
}
protected function FadeBtn_clickHandler(event:MouseEvent):void
{
fadeOut.play();
}
/**
* Updates the console on the screen depending on selectedIndex
*/
private function updateConsole():void{
if(selectedIndex>arrayLength){
selectedIndex = 0;
}
if(selectedIndex<0){
selectedIndex = arrayLength;
}
var rightIndex:int = selectedIndex + 1
var leftIndex:int = selectedIndex - 1
if(rightIndex>arrayLength){
rightIndex=0;
}
if(leftIndex<0){
leftIndex = arrayLength
}
skinLog("===================Console Switched===================");
var debugText:String="SelectedIndex= "+String(selectedIndex)+" ImagePath= "+Console(consoleArray[selectedIndex]).imagePath+" ConsoleName= "+Console(consoleArray[selectedIndex]).consoleName
skinLog(debugText);
skinLog("RightIndex= "+String(rightIndex)+" RightConsole= "+Console(consoleArray[rightIndex]).consoleName);
skinLog("LeftIndex= "+String(leftIndex)+" LeftConsole= "+Console(consoleArray[leftIndex]).consoleName);
consoleLeft.text=Console(consoleArray[leftIndex]).shortName;
consoleCenter.text=Console(consoleArray[selectedIndex]).shortName;
consoleRight.text=Console(consoleArray[rightIndex]).shortName;
label.text=debugText;
image.source=Console(consoleArray[selectedIndex]).imagePath;
}
protected function fadeOut_effectEndHandler(event:EffectEvent):void
{
updateConsole();
fadeIn.play();
}
protected function fadeOut_effectStartHandler(event:EffectEvent):void
{
inTransition = true;
}
protected function fadeIn_effectEndHandler(event:EffectEvent):void
{
inTransition = false;
}
private function keyDown(event:KeyboardEvent):void
{
if(!inTransition){
if(event.keyCode == 37){
selectedIndex--
fadeOut.play();
}
if(event.keyCode == 39){
selectedIndex++
fadeOut.play();
}}
if( event.keyCode == Keyboard.ESCAPE )
{
event .preventDefault();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment