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:
- Caret is inside event attribute of an mxml file:
- Getter and setter can be made bindable if your class implements flash.events.IEventDispatcher (as all Flex components do):
Comments below can no longer be edited.
kenton says:
October 23, 2009Very nice!
Taras Tielkes says:
November 28, 2009It 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
Nick S says:
March 4, 2010This 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!
abhinay says:
July 15, 2016Flash Developer does generate code, and in a lot of cases is better at it.
will says:
August 24, 2012It 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”));
}
}