Created
February 4, 2011 21:47
-
-
Save dermidgen/811843 to your computer and use it in GitHub Desktop.
Aggressively searches for TextFields, and attaches an event listener.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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