4 Replies Latest reply on Nov 22, 2006 11:59 PM by kefas123

    Class with param

    kefas123
      I have this code attach to Tree's iconfunction:

      private function treeIconFunction(item:Object):Class {
      return MyIconClass;
      }
      --------
      package
      {
      import mx.controls.Image;
      import flash.display.Sprite;
      import mx.core.BitmapAsset;
      import mx.core.*;

      public class MyIconClass extends Image
      {
      [Bindable]
      [Embed(source="../../assets/icon.png")]
      public var icon0:Class

      public function MyIconClass():void {
      var color:int=0
      var i:BitmapAsset= new icon0() as BitmapAsset;
      for (var y:uint = 3; y < 6; y++) {
      for (var x:uint = 4; x < 9; x++)
      i.bitmapData.setPixel(x, y, color);
      }
      this.source=i;
      }
      }
      }

      My question is:
      How can send param (item) from treeIconFunction to MyIconClass?
        • 1. Re: Class with param
          ntsiii Level 3
          I think you can send and argument through the constructor, but I don't think that is what you want.

          Why not declare a static function(method) like:
          static function getIcon(whatever:somedatatype):Image?Class

          and in the iconFunction do:
          return MyIconClass.getIcon(whatever);

          Tracy
          • 2. Re: Class with param
            kefas123 Level 1
            quote:

            Originally posted by: ntsiii
            I think you can send and argument through the constructor, but I don't think that is what you want.


            but when i do this:
            return MyIconClass(item.icon);
            i get: : Implicit coercion of a value of type MyIconClass to an unrelated type Class.


            quote:


            static function getIcon(whatever:somedatatype):Image?Class


            What mean this question mark? it is a bug?
            • 3. Re: Class with param
              ntsiii Level 3
              No I am sure you can't do that. Classes do not return anything. You are going to have to create a method on your class to get a return value.

              You MIGHT be able to do:
              var icon:MyIconClass = new MyIconClass(whatever:whateverdatatype);

              "Image?Class" I just don't recall what dataType is required for iconFunction. I recall reading that it needed to be Class.

              Tracy
              • 4. Re: Class with param
                kefas123 Level 1
                quote:

                I recall reading that it needed to be Class.


                So, how can I return class type from MyIconClass?

                Since iconFunction needed to be Class, how builid MyClass?