05 September 2008

Simple Text Field Skins

Not actually a skin, but a simple way to change the way how your text field looks in Flash. Text Field is dynamic with instance name set to 'tField'. First, we set text for our text field. You can put whatever you want. Use '\n' for new line.

tField.text = "your text goes here"

Next we will define few different formats for our text field.

format0 = new TextFormat();
format0.font = "Courier New";
format0.size = 16;
format0.color = 0x000000;

format1 = new TextFormat();
format1.font = "Courier New";
format1.size = 17;
format1.color = 0xFFFFFF;

format2 = new TextFormat();
format2.font = "Courier New";
format2.size = 18;
format2.color = 0x0000FF;

Ok, now we want to create an array and to push formats in it. We do this with next code:

fArray = new Array();

We can control currently displaying format with variable curr, so set:

curr = 0;

When formats will change is up to you. Simplest example is to change format when mouse is released on root movie clip. We need to define next function:

onMouseUp= function(){
if(curr == fArray.length){
curr = 0;
// when curr is equal to array's lenght, we set curr to 0, and cycle formats from the start.


// background change is here just for this example to look better.
if(curr == 1){
tfield.backgroundColor = 0x000000;
tfield.backgroundColor = 0xFFFFFF;

curr += 1; // next format


Click on text field below to see changes.
That's all. If you need fla source file, leave your e-mail.




template by blogger templates