# Check function for textfields in as3?

**URL:** <https://forum.kirupa.com/t/check-function-for-textfields-in-as3/315445>\
**Category:** Uncategorized\
**Created:** [October 26, 2010, 8:49am UTC](https://forum.kirupa.com/t/check-function-for-textfields-in-as3/315445 "2010-10-26T08:49:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![InvisAr](https://avatars.discourse-cdn.com/v4/letter/i/94ad74/32.png) [@InvisAr](https://forum.kirupa.com/u/InvisAr)\
**Post date:** [October 26, 2010, 8:49am UTC](https://forum.kirupa.com/t/check-function-for-textfields-in-as3/315445/1 "2010-10-26T08:49:26Z")

</div>

I’m trying to complete a check function for a input.textfield in AS3.  
In the textfield the user is allowed to type the whole alphabet (swedish alphabet) and after he/she has completed it he/she is supposed to click a correction button to check if it’s right. If it is all the letters are supposed to turn green.  
If not the wrong ones are supposed to turn red and the correct ones green.  
I’ve already tried just simply turning all green if correct and all red if incorrect, but I didn’t get this to work.

Here’s the code:

```php
stop();
import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.text.TextField;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;

var tf:TextField = new TextField();
tf.type = TextFieldType.INPUT;
tf.text = "Skriv alfabetet i rätt ordning!";
tf.x = 250;
tf.y = 250;
tf.height = 800;
tf.width = 800;
var format:TextFormat = new TextFormat();
format.font = "Arial Black";
format.color = Math.random()*0xffffff;
format.size = 50;
tf.setTextFormat(format);
addChild(tf);
tf.restrict = "abcdefghijklmnopqrstuvwxyzåäö";
tf.maxChars = 29;
tf.wordWrap = true;

tf.addEventListener(MouseEvent.CLICK, select);
tf.addEventListener(KeyboardEvent.KEY_DOWN, changeColor);
check_btn.addEventListener(MouseEvent.CLICK, mach);

function select(event:MouseEvent):void
{
    tf.text = "";
    tf.removeEventListener(MouseEvent.CLICK, select);
}

function changeColor(event:Event):void
{    
    var format:TextFormat = new TextFormat();
    format.color = Math.random()*0xffffff;
    if(tf.length>0)
        tf.setTextFormat(format, tf.length-1, tf.length);
}

function mach(event:MouseEvent):void
{
    if(tf.text == "A-Z ÅÄÖ")
    {
        format.color = 0x22e203;
        tf.removeEventListener(KeyboardEvent.KEY_DOWN, changeColor);
    }
    else if(tf.text != "abcdefghijklmnopqrstuvwxyzåäö")
    {
        format.color = 0xdb0a0a;
        tf.removeEventListener(KeyboardEvent.KEY_DOWN, changeColor);
    }
}

```
