7 Replies Latest reply on Feb 12, 2009 7:53 PM by Newsgroup_User

    Custom Component Classes

      Hi all

      I have been learning flex for a few months now and absolutely loving it!
      But there is one thing I can't get my head round. I use to be a Flash user mostly which is probably why I am getting confused....
      I want to be able to make custom components that all use one custom class.
      For example, I have custom canvas components that are 'pages' which I am loading dynamically as and when needed. When they load I want them to fade in using the fade effect. Up until now I have written the code to do this on each component, which is quite annoying considering I have many pages.
      I would like a custom class with the code in it for the fade which every 'page' component uses, so each will fade in when loaded.
      I could this really easily using MovieClips in flash, but flex seems different. Maybe I am getting confused with regards Canvases and MovieClips.

      Please can someone help me? :)

        • 1. Re: Custom Component Classes
          Cesare Rocchi Level 2
          You can create a ComponentWrapper which is extended by your class component like this.

          public class YourCustomComponent extends ComponentWrapper {

          public YourCustomComponent (){}

          ...

          }

          The component wrapper contains a fade method like this.

          public class ComponentWrapper {

          public ComponentWrapper (){}

          public function yourFade() {
          // implement here your fade
          // refer to this.
          }

          }

          HTH

          1 person found this helpful
          • 2. Re: Custom Component Classes
            Thanks _funkyboy, but I am a bit confused now
            I don't have an AS class for the custom components yet. I have only created the components as MXML components. I want to be able to link the MXML components to an AS class. I apologize for my lack of knowledge :p
            • 3. Re: Custom Component Classes
              I almost want to make the MXML components extend an AS Class if that makes any sense
              • 4. Re: Custom Component Classes
                whomba
                you can do this one of two ways

                if your 'custom componets' base class is a canvas you can say

                <mx:Canvas>
                <mx:Script source="some/AS/file" />
                </mx:Canvas>

                or you can just create a custom AS class as _funkyboy described, then create new instances of it like you normally would for other mx tags. Flex builder should be smart enough to put in all the import statments if you don't understand how to

                Hope this helped

                -A
                • 5. Re: Custom Component Classes
                  The thing about _funkyboy's suggestion that confuses me is where do I write that code? As I only have MXML Canvas components I cannot write that code inside them. If I write that code inside my component it tells me I can't have nested classes, which obviously makes sense to me.
                  • 6. Re: Custom Component Classes
                    I am really sorry that I am not understanding the techniques you are suggesting, I just think I need a nudge in the right direction. Do you understand where I am getting confused?
                    • 7. Re: Custom Component Classes
                      Level 7

                      "gamedesign1000" <webforumsuser@macromedia.com> wrote in message
                      news:gn17i4$eha$1@forums.macromedia.com...
                      > Hi all
                      >
                      > I have been learning flex for a few months now and absolutely loving it!
                      > But there is one thing I can't get my head round. I use to be a Flash user
                      > mostly which is probably why I am getting confused....
                      > I want to be able to make custom components that all use one custom class.
                      > For example, I have custom canvas components that are 'pages' which I am
                      > loading dynamically as and when needed. When they load I want them to
                      > fade in
                      > using the fade effect. Up until now I have written the code to do this on
                      > each
                      > component, which is quite annoying considering I have many pages.
                      > I would like a custom class with the code in it for the fade which every
                      > 'page' component uses, so each will fade in when loaded.
                      > I could this really easily using MovieClips in flash, but flex seems
                      > different. Maybe I am getting confused with regards Canvases and
                      > MovieClips.
                      >
                      > Please can someone help me? :)
                      >
                      >

                      Why not just define the effect in the main file and then apply it from the
                      outside, rather than locking your component into one effect:

                      <yourNameSpace:YourCanvas width="200" height="200"
                      creationCompleteEffect="{someEffectYouMade}" />


                      1 person found this helpful