4 Replies Latest reply on Mar 4, 2008 2:37 PM by craigmcdonnell

    Skinning vs Custom UIComponent subclass

    craigmcdonnell
      Hi! I'm currently writing a diagramming tool using Flex Builder 3. I'd like users to be able to add diagram elements of various shapes and be able to add text to these elements, draw link lines between elements, etc.

      Please could someone advise as to whether best practice is to add a programmatic skins to existing container components (such as Canvas) or whether I should really create a custom component extending UIComponent?

      Thanks in advance.
      Craig
        • 1. Re: Skinning vs Custom UIComponent subclass
          Gregory Lafrance Level 6
          I would just use the ActionScript drawing API together with your custom classes for the different shapes you will use. They can inherit from a base class that defines properties and methods common to all the shapes, upon which you can build for each shape's unique aspects.
          • 2. Re: Skinning vs Custom UIComponent subclass
            craigmcdonnell Level 1
            Thanks Greg. I'd be really grateful if you could confirm the amount of effort I should expect to put in to implement this *correctly* :)

            As suggested, I've subclassed UIComponent for my basic shape class and added a UITextField property for the text to be displayed on the shape, (this is something I was working on over the weekend).

            I got this working by taking inspiration from the Flex source code for mx.controls.Button, (I'm actually an undergraduate Computer Science student and am concerned this may be quite a naive approach).

            It does seems like I have reimplement a lot of code to let UITextField know the area in which it can / should display text... Am I doing something wrong or is this to be expected?
            • 3. Re: Skinning vs Custom UIComponent subclass
              Gregory Lafrance Level 6
              Hmmm... Now that I've thought about this a bit more, I'm wondering if you might be better off extending the Button class and as you hinted, use programmatic skins to render the shapes. That way you already have the capability to display text built in.

              I don't really know how long it would take to implement this. It depends on your experience with object oriented and event programming, and with your ability to translate that to using ActionScript. That said, even without heavy experience, if your program is not that ambitious, it might now take long to start getting something working.
              • 4. Re: Skinning vs Custom UIComponent subclass
                craigmcdonnell Level 1
                Thanks for your responses Greg. I guess both options are open then. Thanks to ActionScript being Open Source it's not taken too long to get something working as you say. I guess I'll continue with the approach I've taken so far for now, (extending UIComponent,) as subclassing, e.g. Button, may inherit properties, methods, events and styles that don't really make sense for my diagram element classes.
                Best regards,
                Craig