# \[AS3\] Simple focus example

**URL:** <https://forum.kirupa.com/t/as3-simple-focus-example/273871>\
**Category:** open source\
**Created:** [October 21, 2008, 11:46pm UTC](https://forum.kirupa.com/t/as3-simple-focus-example/273871 "2008-10-21T23:46:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bootiteq](https://avatars.discourse-cdn.com/v4/letter/b/eb9ed0/32.png) [@bootiteq](https://forum.kirupa.com/u/bootiteq)\
**Post date:** [October 21, 2008, 11:46pm UTC](https://forum.kirupa.com/t/as3-simple-focus-example/273871/1 "2008-10-21T23:46:02Z")

</div>

A simple AS3 textField focus example which adds a custom selection glow around the textfeild when it is selected…

Paste into frame 1

```auto

var glowOn = new GlowFilter(0x0099ff,1,4,4,2,1,false);
var glowOff = new GlowFilter(0x0099ff,0,4,4,2,1,false);

function init() {
	for (var i = 0; i<4; i++) {
		var mc = createTextField();
		mc.name = "tf_"+i;
		addChild(mc);
		mc.x = 30;
		mc.y = 30*(i+1);
		mc.addEventListener(Event.CHANGE,traceValue);
		mc.addEventListener(FocusEvent.FOCUS_IN,showSelected);
		mc.addEventListener(FocusEvent.FOCUS_OUT,hideSelected);
	}
}

function createTextField() {
	var tf = new TextField();
	var format = new TextFormat();
	tf.defaultTextFormat = format;
	tf.width =200;
	tf.height =20;
	tf.background = true;
	tf.border = true;
	tf.type = TextFieldType.INPUT;
	return tf;
}

function traceValue(e:Event) {
	trace(e.target.name + ": " + e.target.text);
}

function showSelected(e:FocusEvent) {
	e.target.filters = [glowOn];
}
function hideSelected(e:FocusEvent) {
	e.target.filters = [glowOff];
}
init();

```
