Generating Flex Methods

Posted on by Alexander Doroshko

In Maia, you can easily generate Flex Constructor, Getter, Setter, Event Handler, and toString() methods, and some other stuff by just pressing Alt+Insert when cursor is in *.mxml or *.as file. Let’s have a look at some examples.

  • An option to create Event Handler is available when caret is anywhere inside of a class, but the action behaves in a smarter way when:
    • Caret is inside event attribute of an mxml file:
    • Caret is inside arguments of addEventListener() or removeEventListener() function:
  • Getter and setter can be made bindable if your class implements (as all Flex components do):
Comments below can no longer be edited.

5 Responses to Generating Flex Methods

  1. kenton says:

    October 23, 2009

    Very nice!

  2. Taras Tielkes says:

    November 28, 2009

    It would be nice if the order of the “generate…” entries was not totally different from the Java editor. It’s a small detail, but quite annoying.

  3. Nick S says:

    March 4, 2010

    This is is an essential part of an IDE..the ability to code generate, which is sorely lacking in Flex/Flash Builder.

    I do have one thought on something else which can be added to this to make it even more useful. A lot of the time when Flex developers are using getters/setters it is so that we can hook into calling invalidateDisplayList/invalidateProperites/etc. A big part of this is setting a flag so that when the call to commitProperties/etc is invoked, it can check for those flags and act accordingly.

    The basic format is as follows:

    private var _foo:Object;
    private var _fooChanged:Boolean = false;

    public function set foo(value:Object):void
    _foo = value;
    _fooChanged = true;

    public function get foo():Object
    return _foo;

    override protected function commitProperties()

    If there were some way to generate the getters/setters where they include that accompanying boolean flag as well as call one or more of the invalidatexxx functions..that would be MONEY! I can’t tell you how many times I write that!

    Bonus points if you can add the fooChanged..block to the function which we are scheduling a call to.

    Another awesome thing would be to highlight a public var and then convert it to this private getter/setter format(and vice versa)


    • abhinay says:

      July 15, 2016

      Flash Developer does generate code, and in a lot of cases is better at it.

  4. will says:

    August 24, 2012

    It would be even better to expose the getter/setter as a template, so a developer might rewrite it as:

    public set foo(afoo:String) : void
    if(_foo != afoo)
    _foo = afoo;
    dispatchEvent(new Event(“fooChanged”));


Subscribe for updates