4 Replies Latest reply on Sep 25, 2006 5:32 PM by ntsiii

    Referencing parent from custom components

    looklisten Level 1
      I'm starting a project with multiple developers and want to split it up across a collection of mxml files by using custom components (the Flex Store example does this for it's three states).

      Is there any way to reference scripts in the parent document in which the components are embedded and not have the cc throw errors when compiled?
        • 1. Re: Referencing parent from custom components
          ntsiii Level 3
          I am not sure I understand what you want with your work flow. Each developer is going to need a copy of the full app to develop / compile / test his component. They will at least need a test harness of some sort that mimics the interface. Flex Builder is not very effective at building and compiling and testing components alone.

          Or are you asking how in general to reference members of the parent from within a child?

          Tracy
          • 2. Re: Referencing parent from custom components
            looklisten Level 1
            Yes, the latter. I'm breaking the project into pieces (custom components), with the container including the child objects. I want to know how to have a script in the parent container that is able to reference objects in the child, without the compiler generating errors because it can't find those references at compile team and sees them as invalid (and vice-versa). This has to be possible! Thanks for your help.
            • 3. Re: Referencing parent from custom components
              Ed_Syrett Level 1
              Hi looklisten,

              I think I understand what you want to do, and here's some suggestions.

              You have a parent container in which you want to put several components, and your first step is to create a base class for your components eg:

              public class BaseComponent extends Canvas
              {
              etc...

              }

              Any behaviour that is common to all your child components goes in here. Just for starters, you might want to have all components have a pointer to your container, so you might start off with this....

              public class BaseComponent extends Canvas
              {
              private var _parent:MyContainer;

              public function set parentContainer(container:MyContainer):void
              {
              _parent = container;
              }
              }

              Then your parent container (MyContainer in the example) only needs to have a list of references to BaseComponent, and doesn't care what type they are as long as they are derived from BaseComponent. I don't know if you have any Object Orented Design experience, but this is a step in that direction.....


              • 4. Re: Referencing parent from custom components
                ntsiii Level 3
                This is not a Flex Builder question. Next time post in the appropriate forum.

                You can access members in the application scope from within a child component (at any depth of nesting) like this:
                Application.application.myVariable.

                Also see the docs for the parentDocument property.

                Tracy