Friday, 30 May 2008

Type on stage

This flash tutorial will teach you how to type keyboard characters on the stage. This tutorial is pretty simple and requires using Actionscript 2.0.

Type on stage

Step 1

Open a new Flash document.
Select the dynamic text tool and drag a rectangular shape on the stage like below:




Step 2

Using the selection tool (V) select the dynamic text box on the stage and set the line type to multiline and change the instance name to “out_txt”.




Step 3

On the timeline insert a new layer called “Actions”.
Right click on the first frame select Actions and enter the following code:



var outText:String;
listenerObject = new Object();
listenerObject.onKeyDown = function() {
keyChar=Key.getAscii();
switch (keyChar) {
case 97 :
out_txt.text = out_txt.text+"a";
break;
case 98 :
out_txt.text = out_txt.text+"b";
break;
case 99 :
out_txt.text = out_txt.text+"c";
break;
case 100 :
out_txt.text = out_txt.text+"d";
break;
case 101 :
out_txt.text = out_txt.text+"e";
break;
case 102 :
out_txt.text = out_txt.text+"f";
break;
case 103 :
out_txt.text = out_txt.text+"g";
break;
case 104 :
out_txt.text = out_txt.text+"h";
break;
case 105 :
out_txt.text = out_txt.text+"i";
break;
case 106 :
out_txt.text = out_txt.text+"j";
break;
case 107 :
out_txt.text = out_txt.text+"k";
break;
case 108 :
out_txt.text = out_txt.text+"l";
break;
case 109 :
out_txt.text = out_txt.text+"m";
break;
case 110 :
out_txt.text = out_txt.text+"n";
break;
case 111 :
out_txt.text = out_txt.text+"o";
break;
case 112 :
out_txt.text = out_txt.text+"p";
break;
case 113 :
out_txt.text = out_txt.text+"q";
break;
case 114 :
out_txt.text = out_txt.text+"r";
break;
case 115 :
out_txt.text = out_txt.text+"s";
break;
case 116 :
out_txt.text = out_txt.text+"t";
break;
case 117 :
out_txt.text = out_txt.text+"u";
break;
case 118 :
out_txt.text = out_txt.text+"v";
break;
case 119 :
out_txt.text = out_txt.text+"w";
break;
case 120 :
out_txt.text = out_txt.text+"x";
break;
case 121 :
out_txt.text = out_txt.text+"y";
break;
case 122 :
out_txt.text = out_txt.text+"z";
break;
case 32 :
out_txt.text = out_txt.text+" ";
break;
}
};
Key.addListener(listenerObject);



**This code above basically detects every key stroke and displays the character in the dynamic text box.


Step 4

Test your movie Ctrl + Enter.
Now type some character on your keyboard and you should see the following character on the stage.

0 comments:

  COPYRIGHT © 2014 · ILIKE2FLASH · Theme by Ourblogtemplates

Back to TOP