1 Reply Latest reply on Oct 25, 2007 8:33 PM by ntsiii

    How to refer to an object by variable

    smokinjoefission
      Hi all,

      I'm quite new to Flex so please forgive my newbieness. I'm not even sure how to phrase a search for the solution to my question, so I'm sorry if this has been discussed before:

      I have a form with 2 states that a user is to fill out and submit to my server (step 1, step 2, no problem, I've got that far). I want to have the contents of each field saved into a local shared object as the user fills out the information (again, no problem I've got that figured out) as it's a lengthy process and the user can close their browser and come back to where they left off at a later time without having to re-enter everything.

      I'm saving the information in the shared object using the object's id as a key. Example: mySharedObject.companyName = companyName.text

      Where I'm getting stumped is when the user comes back to the the form, and the previously entered data is drawn from the shared object, how can I reference the original form object from the shared object's key? Part of my problem is that some of the text forms are contained within another container (such as a canvas), so it's not as simple as iterating through the objects in the application and assigning the saved values based on a comparison of the objects id.

      Any guidance in the right direction would be greatly appreciated.

      Thanks,
      Krys
        • 1. Re: How to refer to an object by variable
          ntsiii Level 3
          You might have to store that path information in the lso.

          For example, the "key" might be "app.component1.component12.componentX".

          You woul dhave to parse that string:
          aPath:Array = key.split(".") ;

          and at each step, get a referenct to the corresponding component.

          So at your main app level, you might do:
          var target:UIComponent = this[aPath[1]];
          target = target[aPath[2]];
          ...

          But actually, that is kind of crazy.

          Instead, put your data in some known structure at the main app level, say an associative array, then in each component, when it instantiates, maybe the creattionComplete event, call up to the main app and retrieve the values you want.

          Tracy