1 Reply Latest reply on Mar 1, 2008 11:27 AM by VarioPegged

    Help about creating a custom class

    omurdd
      I created a custom class that extends to Shape class. It has two additional variables, name and coordinates. I want to store information of all my buildings in an array called myData:Array which will consist of my custom class Building(s) in it. So every item in first line in my Array is in Building Type. (Remember a type that extends Shape). I can summarize like this:

      myData:Array
      myData[0]:Building
      name:String
      coordinates:Array
      myData[1]:Building
      name:String
      coordinates:Array

      Problem is i can not add my Building object myData[0] to a Canvas it says "TypeError: Error #1034: Type Coercion failed: cannot convert Bina@127924a1 to mx.core.IUIComponent."

      Solutions are welcome !


        • 1. Re: Help about creating a custom class
          VarioPegged Level 2
          To add a child to any container (Canvas, Application, etc.) in Flex, that child must implement the IUIComponent interface. The Shape class doesn't implement IUIComponent, so that's why you're getting the error.

          You could implement IUIComponent in your custom class, but it may be easier to use a different approach, like extending UIComponent and then setting your variables within that class.

          See if the following works for you (part of a previous post of mine)...

          package
          {
          import mx.core.UIComponent;
          import flash.display.Shape;
          public class ShapeClass extends UIComponent
          {
          public function ShapeClass()
          {
          super();
          drawShape();
          }
          private function drawShape():void
          {
          var child:Shape = new Shape();
          child.graphics.beginFill(0x000000);
          child.graphics.drawRect(100, 100, 100, 100);
          child.graphics.endFill();
          addChild(child);
          }
          }
          }

          TS