Love AS3 but on this point it is driving me nuts…
My project simulates an application. Each frame in the Flash file contains a bitmap of a state of the application. I use TextFields (placed in Flash, not AS) that accept input.
This example provides a simplification of my problem:
Frame 1: contains 3 TextFields, instance names: input1_txt, input2_txt, input3_txt
Frame 2: contains 1 TextField, instance name: input1_txt
The code reads the input from each frame by referencing the instance names. One can also navigate between frames.
I can process inputs on Frame 1, then move to Frame 2, and process the input. However, if I go back to Frame 1 the reference no longer works. Strangely I can go back and forth between frames if I don’t enter any input and it works when I do. But as soon as I enter any input it breaks (object reference not found) on later attempts on the same frame.
On each frame there is code that saves the TextField references in an array for later processing (e.g., var myFields:Array = [input1_txt, input2_txt, input3_txt]). After this failed I tried saving the names as strings and getting to them by: container_mc[input1_txt]. Same problem as before.
I read on this forum that referencing objects created on the stage by Flash is not the same as creating the object in AS code. Fair enough. I ought to be able to find it using container_mc.getChildByName(input1_txt). However, that returns a display object and I need to get the text from it.
I tried using unique names for all input fields, but that didn’t work.
From a design point of view I would like to be able to draw the fields on each frame with the Text tool and then use Flash to work with them. But I am pulling out my hair trying to figure out a reliable way to reference them each time.
My design uses a new instance of a custom ScreenData object on each frame. I use the same variable on each frame (e.g. sData = new ScreenData). Then the object saves the references by instance name (e.g. sData.inputFields = [input1_txt, input2_txt, input3_txt]). I then use a keyboard event (setup on first frame to be global) to send the data for processing (e.g. var isSuccessful = ScreenUI.process(sData)).
What to do???