Generating Flex Methods

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 flash.events.IEventDispatcher (as all Flex components do):
This entry was posted in New Features and tagged , . Bookmark the permalink.

4 Responses to Generating Flex Methods

  1. kenton says:

    Very nice!

  2. Taras Tielkes says:

    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.

    http://youtrack.jetbrains.net/issue/IDEA-25806

  3. Nick S says:

    This is fantastic..it 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;
    invalidateProperties();
    }

    public function get foo():Object
    {
    return _foo;
    }

    override protected function commitProperties()
    {
    super.commitProperties();
    if(fooChanged)….
    }

    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)

    Thanks!

  4. will says:

    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”));
    }
    }

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">