1 Reply Latest reply on Jul 26, 2006 5:45 PM by ntsiii

    Passing References to Objects

      How do I pass a reference to an ActionScript object between Flex components? Specifically, I have a custom component that consists of a login form. When the user submits the form I want to create a user object that I can use later. So after I submit the form and create this object, how do I pass it back?

      Alternatively, I could create a default object in the main page and pass a reference to it to the custom component where I could set its properties. Of course I would need the changes to persist. But I don't know how to pass that reference.

      Does anyone know how I would solve this?

        • 1. Re: Passing References to Objects
          ntsiii Level 3
          This is not a Flex Builder question, so next time please pay attention to which forum you post a question in.

          To pass a reference into a component, create either a public variable or a setter function in the component:
          public var MyPassedInObjectReference:MyOtherCustomComponent ; //IMPORTANT: always type this variable as specifically as possible! Avoid Object!

          Then in the mxml that instantiates the custom component:
          <myNamespace:MyOtherCustomComponent id="MyOtherComponent".../>
          <myNamespace:MyCustomComponent id="whatever" MyPassedInObjectReference="{MyOtherComponent }" .../>

          Now, from within MyCustomComponent, you can do:
          MyPassedInObjectReference.someVariableInThatComponent = someVaraibleInThisComponent;
          someVaraibleInThisComponent = MyPassedInObjectReference.someFunctionInThatComponent();

          Note: for component re-usability, consider using events.