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

    Building components from Abstract component

    Rogier_Doekes
      Hello,

      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)">
      <mx:MetaData>
      [Event name="click", type="com.my.events.ClickEvent")]
      </mx:MetaData>
      <mx:Script>
      <![CDATA[
      import flash.events.MouseEvent;
      import com.my.events.ClickEvent;
      [Bindable]
      public var iconNormal:Class;
      [Bindable]
      public var iconHot:Class;
      [Bindable]
      public var text:
      private function handler(event:MouseEvent):void
      {
      theImage.source = iconHot;
      this.dispatchEvent(new ClickEvent(ClickEvent.CLICK));
      }
      ]]>
      </mx:Script>
      <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" >
      <mx:Script>
      <![CDATA[
      [Embed (source="/assets/icons/normal/iconAdd.png")]
      public iconNormal:Class;

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

      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