1 Reply Latest reply on May 3, 2011 8:09 AM by CleanCoder

    Dynamically add pre-created components to a skin

    sparkplugXL

      Hi, it's been an interested couple of days digging into SPARK, but I think there's something I really haven't understood :

       

      I have a pre-created set of SkinnableComponents (instantiated via Swiz IoC).  I would like to be able to dynamically pick one of these components, and add/remove it from within another mxml component which acts as a visual "frame".

       

      With Halo, obviously, not a problem... "addChild" and "defaultPlacement" would do the job... but with Spark I'm scratching my head...

       

      I guessed that I would define my "Frame" Skin as something like :

       

       

      ...declare a [SkinPart] in the corresponding component :

       

      [SkinPart(type="spark.components.supportClasses.SkinnableComponent")] public var mySection : SkinnableComponent;

       

      ...and then dynamically assign "mySection" with the pre-created SkinnableComponents on demand.

       

      Problem 1 :

       

      Error: Skin for BMClientPrototype0.WindowedApplicationSkin5.Group6.contentGroup.HGroup10.menu_stage.MenuS tageSkin39.mySection cannot be found.

       

      Also, the documentation is confusing me. The documentation on dynamic skin parts doesn't seem relevant (I don't want to create fresh components from a factory, I want to use pre-instantiated components).

       

      To be honest, I'm generally feeling quite lost at the moment...

       

      What would be roughly the right way to go about creating a custom component which accepts pre-created SkinnableComponents, and goes about adding them as children (within its own custom skin)?

       

      Many thanks,

       

      B

        • 1. Re: Dynamically add pre-created components to a skin
          CleanCoder Level 2

          When you call addElement on SkinnableComponent, the element being added automatically gets added to the "contentGroup" skin part, which is a Group belongs to your skin. In other words, by calling addElement or removeElement on your SkinnableContainer, you are actually adding and removing element from your skin automatically. At first glance it does not seem like you need to create your custom components as skin parts, try simply adding them by using addElement().