1 Reply Latest reply on Jan 10, 2007 7:49 AM by FlightGuy

    Use custom AS  Class in MXML

    Camus Miu

      I have a custom class which extend button, and parameters is needed in constructor.

      when I try to put the class in MXML as visual compoents such as <mx:customButton />

      ArgumentError: Error #1063: Argument count mismatch on ____ Expected 0, got 1.

      Appearently the parameters for the constructor is missed. but how can i pass the parameters in the tag?

      Thanks in advances.

        • 1. Re: Use custom AS  Class in MXML
          FlightGuy Level 1
          You can't use arguments on the constructor in MXML. Aside of anything else, there's no way to pass them. Your options are - if you want to use the same component from AS and really want those constructor arguments, is to make them optional:

          public customButton(myArg:String=null)...

          The attributes specified in the MXML will be assigned to public properties by the same name once the instance has been created. So if you want to be able to say:

          <mx:customButton myArg="hello"/>

          You'll need to do something like:

          public class customButton extends Button{
          public var myArg:String;

          By the way it's conventional to use uppercase to start the name of a class, and lowercase to start the name of an instance. So it would be conventional to call your class CustomButton.