5 Replies Latest reply on Aug 31, 2007 10:39 AM by Rogier_Doekes

    Building components from Abstract component


      I am a litte confused about using Abstract classes in which you define the common fields and methods a component might need.

      Consider my scenario:
      I am building more than a handful clickable icons. The click is always handled by dispatching an event.

      Each class consist of two controls: <mx:Image> and <mx:Text>. The Image should source an embedded image while the text displays a more verboose description of the same process. Something like this:
      --add icon-- Add Customer information
      --display icon-- Display Customer information etc.

      My Abstract class AbstractIcon.mxml looks like this:
      <mx:HBox xmlns:mx=" http://www.adobe.com/2006/mxml" mouseUp="handler(event)">
      [Event name="click", type="com.my.events.ClickEvent")]
      import flash.events.MouseEvent;
      import com.my.events.ClickEvent;
      public var iconNormal:Class;
      public var iconHot:Class;
      public var text:
      private function handler(event:MouseEvent):void
      theImage.source = iconHot;
      this.dispatchEvent(new ClickEvent(ClickEvent.CLICK));
      <mx:Image id="theImage" source="{ iconNormal}"/>
      <mx:Text selectable="false" text="{ text }"/>

      Now I would like to implement this as a iconAdd.mxml
      <icons:AbstractIcon xmlns:icons="com.ny.icons.*" xmlns:mx=" http://www.adobe.com/2006/mxml" >
      [Embed (source="/assets/icons/normal/iconAdd.png")]
      public iconNormal:Class;

      [Embed (source="/assets/icons/hot/iconAdd.png")]
      public iconHot:Class;

      However this code breaks: something about member conflict in the AbstractIcon class. Also adding the override keyword is no use, as only methods can be overwritten.

      How would I make the components as such that I am able to add a lot of icons components using the Abstract component?
      I really like this concept, since all the layout changes (such as font type, size, colors etc) are all handled in the AbstractIcon class without the need to change each individual components.

      Thanks for any help,

      -Rogier Doekes