10 Replies Latest reply on Apr 23, 2009 4:45 PM by Seglespaan

    Custom Components

    Seglespaan Level 1

      Hi,

       

      Say i have a flex application called a.mxml and inside the components folder i have a component called b.mxml

       

      a.mxml containts a textInput box called input, and b contains a textArea called echoInput.

       

      how do I get echoInput to have the same value as Input.

       

      I've tried this but to no avail

       

      <mx:TextArea id="echoInput" text="{components.b().input.text}" />

       

       

      I have set up my namespace as follows xmlns:comp="components.*" and the component is recognised within the main app, but just can't seem to get it to work!

       

      Cheers

        • 1. Re: Custom Components
          Seglespaan Level 1

          while I'm at it,

           

          if i have ten combo boxes populated by ten different arrays, can I save all my arrays in an arrays file and still use them as data providers for comboboxes within my components!

           

          spot the newb! lol

          • 2. Re: Custom Components
            Michael Borbor Level 4

            Lets say you add your component to your main app and do this

            <comps:b id="myComp" />
            
            <mx:TextArea id="echoInput" text="{myComp.text}" />
            

            Yes you can store in a single file all your arrays and use them at your discretion

            • 3. Re: Custom Components
              Seglespaan Level 1

              when u put it like that is seems so easy, and well it makes alot more sense, as you may have 20 of the same component on screen each with different ids thus being able to manipulate 20 different other things.

               

              Rather than my train of thought in which the component would always only effect one thing!

               

              Awesome.

               

               

              As for the arrays,

               

              is it essentially identical? i.e. have a component called arrays, in which theres 5 arrays with different ids,

               

              then in the main app I have to use

               

              <comp:array1 id="array1">

               

              then use

               

              dataprovider = {array1}

               

              is that the best way of doing it, is there another way that doesn't require you to add the array to the main app?

              • 4. Re: Custom Components
                Michael Borbor Level 4

                I'll say that it'll be better if you create an actionscript file with all your arrays and the import that actionscript file into your main app or components.

                • 5. Re: Custom Components
                  Seglespaan Level 1

                  Cheers,

                   

                  thanks for you help

                  • 6. Re: Custom Components
                    Michael Borbor Level 4

                    You're welcome, glad I was able to help. Please don't forget to close the thread.

                    • 7. Re: Custom Components
                      ntsiii Level 3

                      This might be a good place to step in with the suggestion to look into using a data model.  Rather than wirirng individual ui components to each other, you woulod have a central location, a component, where you keep all of your shared data elements.  You make that class or the individual properties [Bindable] and then bind you UI elements to the appropriate property.

                       

                      Often the "singleton" pattern is used for this.  I find it very useful and easy to work with.  So in component "b", yo might write:

                      ...text="{MyModel.getInstance().mySharedData}"

                      • 8. Re: Custom Components
                        Seglespaan Level 1

                        Ok, so from what you've said ntsiii, rather than creating ten custom components I create one large component that contains the ten.

                         

                        Obviously the point of creating components in the first place is to be able to re-use the component over and over withought having to recode it. but for large projects would this method not get rather messy, and lead to an absolutley massive central location file.

                         

                        Is this method faster? less resource hungry??

                        • 9. Re: Custom Components
                          ntsiii Level 3

                          You have a single model component for *shared* or global data, that is data that need to be read or written from different places in your application.

                           

                          You still code you UI elements however you wish.

                           

                          The benefit is maintainability.  If your data is stored in a model, and you later add a component that needs to access that data, you will know where it is.  further if you find you need to "clear" that data, or modify it from somewhere not forseen, like on log-out, then you can simply set the data in the model and all ui elements will reflect it.

                          • 10. Re: Custom Components
                            Seglespaan Level 1

                            so essentially this is what michael suggeted in his second last post with the actionscript file,

                             

                            thus if I wanted to populate a comboBox from a table in a database, a section of the data Model would collect this data which i could then use within my application, rather than having to collect this data each time i wanted to use it i would just reference that part of my data model?