5 Replies Latest reply on Jan 27, 2009 2:00 PM by chrun

    Finding properties of component

    chrun
      Hi
      I was wondering if anyone could give me a tip on how to do this...

      I am trying to seperate my code and MXML components a bit more. Currently I am lumping everything together in one awful MXML file. It's going just fine, I have value objects storing values and seperate classes for functions and all of that lovely stuff going on...

      The problem is accessing the values of components. For instance, I have a canvas in my main app "myCanvas" containing a number of children.

      I would usually just do myCanvas.numChildren() to find out how many children.

      I would like to somehow do this with my external classes. I guess I would just like to know the accepted method of sharing component properties throughout the classes I am using.

      Thanks a lot for any help whatsoever

      Chris
        • 1. Re: Finding properties of component
          Level 7

          "chrun" <webforumsuser@macromedia.com> wrote in message
          news:gllrpb$orf$1@forums.macromedia.com...
          > Hi
          > I was wondering if anyone could give me a tip on how to do this...
          >
          > I am trying to seperate my code and MXML components a bit more. Currently
          > I am
          > lumping everything together in one awful MXML file. It's going just fine,
          > I
          > have value objects storing values and seperate classes for functions and
          > all of
          > that lovely stuff going on...
          >
          > The problem is accessing the values of components. For instance, I have a
          > canvas in my main app "myCanvas" containing a number of children.
          >
          > I would usually just do myCanvas.numChildren() to find out how many
          > children.
          >
          > I would like to somehow do this with my external classes. I guess I would
          > just
          > like to know the accepted method of sharing component properties
          > throughout the
          > classes I am using.
          >
          > Thanks a lot for any help whatsoever

          If your classes are based on UIComponent, they will already have the
          numChildren() function inbuilt. If they're data classes, write an interface
          with the functions you expect to use and implement it on your classes. Then
          you can cast your classes to IWhatever instead of the actual class, and Flex
          will know you can do myIWhatever.numChildren(), regardless of the specific
          class.

          HTH;

          Amy


          • 2. Re: Finding properties of component
            cc242242
            Hey Amy thanks for answering. I am using a standard UIComponent (it's a canvas). I guess what I need to do is to be able to access it's properties application-wide. I have used a ValueObject singleton to do the same thing with variables and a singleton class to make functions available application-wide. (just learning this stuff). The problem is making the properties of the Canvas visible application-wide

            So I have my main mxml document with this canvas "myCanvas".

            I have another class with a load of functions. I would like to have a function in there which returns myCanvas.numChildren() but obviously myCanvas is not available to other classes at this point.

            I am just not sure how to create the UIComponent and make it's properties known application-wide

            Thanks again for your reply

            • 3. Re: Finding properties of component
              Gregory Lafrance Level 6
              You could use a MVC architecture to make it easier to access properties / methods application wide.

              Or you could use custom events to pass data around, and ensure the desired data are properties of the event object.

              Or you could use the Application.application property, or parentApplication, parentDocument.
              • 4. Re: Finding properties of component
                Level 7

                "Greg Lafrance" <webforumsuser@macromedia.com> wrote in message
                news:glndl1$npq$1@forums.macromedia.com...
                > You could use a MVC architecture to make it easier to access properties /
                > methods application wide.
                >
                > Or you could use custom events to pass data around, and ensure the desired
                > data are properties of the event object.
                >
                > Or you could use the Application.application property, or
                > parentApplication,
                > parentDocument.
                >

                Check out
                http://www.adobe.com/devnet/flex/articles/loose_coupling.html
                http://www.adobe.com/devnet/flex/articles/graduating_pt1.html


                • 5. Re: Finding properties of component
                  chrun Level 1
                  Hi Greg and Amy. Thanks a lot for those replies - exactly what I was after, really useful stuff.