Generating Flex Methods
October 23rd, 2009 by Alexander DoroshkoIn 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):
October 23rd, 2009 at 9:38 am
Very nice!
November 28th, 2009 at 9:13 am
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
March 4th, 2010 at 2:35 pm
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!