Skip to content

Instantly share code, notes, and snippets.

@dermidgen
Created February 4, 2011 21:47
Show Gist options
  • Save dermidgen/811843 to your computer and use it in GitHub Desktop.
Save dermidgen/811843 to your computer and use it in GitHub Desktop.
Aggressively searches for TextFields, and attaches an event listener.
/**
* Note - you'll need:
* import flash.events.FocusEvent
*
* Also, try/catch is pretty expensive processing-wise. Avoid it.
* I threw it together that way so you can play with it and get some
* better reporting on what's going on without it bombing on you.
* Once you refine it to search without throwing any exceptions on
* missing properties or methods, kill the try/catch.
*/
function saveField(e:FocusEvent):void {
var fieldName:String = e.target.name;
var fieldValue:String = e.target.text;
// Save
}
function findFields(rootContainer:DisplayObjectContainer):void {
for(var i=0; i < rootContainer.numChildren; i++) {
var item:* = rootContainer.getChildAt(i);
try { // Let's see if we have a textfield
if (item.getQualifiedClassName() == "flash.text.TextFormat") {
item.addEventListener(FocusEvent.FOCUS_OUT, saveField)
}
else { // Nope - let's try to keep digging
findFields(item);
}
} catch (e:Error) {
trace(e.toString());
}
}
}
findFields(root);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment