|
|
var letters:Array=new Array(”a”,”b”,”c”,”d”,”e”);
var myRandomNumber:Number=Math.floor(Math.random()*5);
my_txt.text=letters[myRandomNumber];
my_keyboardText.text=”Key Pressed:”;
stage.addEventListener(KeyboardEvent.KEY_UP, keyUsed);
function keyUsed(event:KeyboardEvent)
{
var str:String=my_txt.text;
my_keyboardText.text=”Key Pressed: “+String.fromCharCode(event.charCode);
if (event.charCode==str.charCodeAt(0))
{
my_txt.text=”Correct”;
} else
{
my_txt.text=”Wrong”;
}
}
Source:
abc
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
//*********************************************************************
//************************** 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 = [...]
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
//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
var myBox1:Box = new Box();
var myBox2:Box = new Box();
var myBox3:Box = new Box();
myBox1.x=125;
myBox1.y=125;
myBox2.x=150;
myBox2.y=150;
myBox3.x=175;
myBox3.y=175;
addChild(myBox1);
addChild(myBox2);
addChild(myBox3);
myBox1.buttonMode=true;
myBox2.buttonMode=true;
myBox3.buttonMode=true;
myBox1.addEventListener(MouseEvent.CLICK, clickMe);
myBox2.addEventListener(MouseEvent.CLICK, clickMe);
myBox3.addEventListener(MouseEvent.CLICK, clickMe);
function clickMe(event:MouseEvent)
{
setChildIndex(MovieClip(event.currentTarget),numChildren-1);
}
Source:
SettingSpriteDepth
var mySprite1:Sprite = new Sprite();
mySprite1.graphics.lineStyle(2,0×000000);
mySprite1.graphics.beginFill(0×992300);
mySprite1.graphics.drawCircle(0,0,100);
mySprite1.x = 100;
mySprite1.y = 100;
addChild(mySprite1);
mySprite1.buttonMode=true;
var mySprite2:Sprite = new Sprite();
mySprite2.graphics.lineStyle(2,0×000000);
mySprite2.graphics.beginFill(0×992300);
mySprite2.graphics.drawCircle(0,0,100);
mySprite2.x = 300;
mySprite2.y = 100;
addChild(mySprite2);
mySprite2.buttonMode=true;
var mySprite3:Sprite = new Sprite();
mySprite3.graphics.lineStyle(2,0×000000);
mySprite3.graphics.beginFill(0xffffff);
mySprite3.graphics.drawCircle(0,0,25);
mySprite3.x = 0;
mySprite3.y = 0;
mySprite1.addChild(mySprite3);
mySprite1.addEventListener(MouseEvent.CLICK, clickSprite);
mySprite2.addEventListener(MouseEvent.CLICK, clickSprite);
function clickSprite(event:MouseEvent) {
event.currentTarget.addChild(mySprite3);
}
Source:
SpriteGroup_OneButtonListener-canBeUsedForMultipleButtons
var myTextFormat:TextFormat = new TextFormat();
myTextFormat.size=14;
myTextFormat.font=”Tahoma”;
myTextFormat.bold=true;
myTextFormat.color=0xff0000;
var myStyle:StyleSheet = new StyleSheet();
myStyle.setStyle(”a”,{textDecoration:”underline”, color:”#3080d2″});
var myText:TextField = new TextField();
myText.defaultTextFormat=myTextFormat;
myText.styleSheet=myStyle;
myText.x=20;
myText.y=20;
myText.width=550;
myText.height=34;
myText.htmlText=”Visit www.flash-templates-today.com!”;
addChild(myText);
var myText2:TextField = new TextField();
myText2.defaultTextFormat=myTextFormat;
myText2.styleSheet=myStyle;
myText2.x=20;
myText2.y=50;
myText2.width=550;
myText2.height=34;
myText2.htmlText=”You can click here!”;
addChild(myText2);
var myTextMsg:TextField = new TextField();
myTextMsg.defaultTextFormat=myTextFormat;
myTextMsg.styleSheet=myStyle;
myTextMsg.x=20;
myTextMsg.y=100;
myTextMsg.width=300;
myTextMsg.height=30;
myTextMsg.text=”link was clicked”;
myTextMsg.visible=false;
addChild(myTextMsg);
addEventListener(TextEvent.LINK, clickHere);
function clickHere(event:TextEvent):void
{
trace(event.text);
myTextMsg.visible=true;
}
Source:
LinkedText
var myTextFormat:TextFormat = new TextFormat();
myTextFormat.font=”Tahoma”;
myTextFormat.size=32;
myTextFormat.bold=true;
var myText:TextField = new TextField();
myText.defaultTextFormat = myTextFormat;
myText.text=”Hello world!”;
myText.x=150;
myText.y=100;
myText.width=220;
myText.height=42;
myText.border=true;
myText.selectable=false;
addChild(myText);
Source:
DrawingText
this.graphics.lineStyle(4,0xFF0000);
this.graphics.moveTo(200,200);
this.graphics.lineTo(250,250);
this.graphics.curveTo(300,300,350,250);
this.graphics.lineTo(400,200);
this.graphics.drawRect(0,0,100,100);
this.graphics.drawRoundRect(0,120,100,100,45,45);
this.graphics.drawCircle(50,250,10);
this.graphics.drawEllipse(50,300,30,90);
this.graphics.beginFill(0×122da3);
this.graphics.drawCircle(300,230,20);
this.graphics.endFill();
Source:
drawingLine
|
|