February 2010
M T W T F S S
« Jan   Mar »
1234567
891011121314
15161718192021
22232425262728

Localization

import fl.lang.Locale;
Locale.autoReplace=true;

var IDS_TEXT:Object=test_text;
var IDS_TEXT2:Object=test_text2;
var IDS_TEXT3:Object=test_text3;

Locale.setLoadCallback(updateText);
function updateText(success:Boolean):void
{
var arr=Locale.stringIDArray;
for (var i = 0; i < arr.length; i++)
{
this[arr[i]].text=Locale.loadString(arr[i]);
}
}

// load default language
Locale.loadLanguageXML(”en”);

// buttons
en_bt.addEventListener(”click”,en_select);
ru_bt.addEventListener(”click”,ru_select);

function en_select(event:Event)
{
Locale.loadLanguageXML(”en”);
}
function ru_select(event:Event)
{
Locale.loadLanguageXML(”ru”);
}

Source:

localization

Understanding Text Input

//*********************************************************************
//************************** Text input *****************************
//*********************************************************************
var myTitleText:TextField = new TextField();
myTitleText.width=400;
myTitleText.text=”enter something and click enter;)”;
addChild(myTitleText);

var inputMyFormat:TextFormat = new TextFormat();
inputMyFormat.font = “Tahoma”;
inputMyFormat.size = 14;
inputMyFormat.color = 0xff0000;
inputMyFormat.bold=true;

var myInputText:TextField = new TextField();
myInputText.type = TextFieldType.INPUT;
myInputText.defaultTextFormat = inputMyFormat;
myInputText.x = 10;
myInputText.y = 30;
myInputText.height = 18;
myInputText.width = 200;
myInputText.border = true;
stage.focus = myInputText;
addChild(myInputText);

myInputText.addEventListener(KeyboardEvent.KEY_UP, checkForReturn);
function checkForReturn(event:KeyboardEvent) {
if (event.charCode == 13) {
acceptInput();
}
}

function acceptInput() {
var theInputText:String = [...]

Understanding keyboard input

my_keyboardText.text=”Key Pressed:”
my_spacebarText.text=”Spacebar is Up”

stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownFunction);
function keyDownFunction(event:KeyboardEvent) {
my_keyboardText.text = “Key Pressed: “+String.fromCharCode(event.charCode);
if (event.charCode == 32) {
my_spacebarText.text = “Spacebar is DOWN.”;
}
}

stage.addEventListener(KeyboardEvent.KEY_UP, keyUpFunction);
function keyUpFunction(event:KeyboardEvent) {
if (event.charCode == 32) {
my_spacebarText.text = “Spacebar is UP.”;
}
}

Source:

KeyboardInput

Understanding mouse input

//Updating mouse location
addEventListener(Event.ENTER_FRAME, showMouseLocation);
function showMouseLocation(event:Event) {
my_txt.text = “X=”+mouseX+” Y=”+mouseY;
}

//When user rollover to my_mc code change alpha to .5
my_mc.addEventListener(MouseEvent.ROLL_OVER, rolloverSprite);
function rolloverSprite(event:MouseEvent) {
my_mc.alpha = .5;
}

//When user rollout to my_mc ocde change alpha to 1
my_mc.addEventListener(MouseEvent.ROLL_OUT, rolloutSprite);
function rolloutSprite(event:MouseEvent) {
my_mc.alpha = 1;
}

Source:

MouseInput