07 12 / 2012
Autocomplete addEventListener constants in AS3
I’ve been having some difficulty getting Flash Builder to autocomplete event type constants on addEventListener. Seems like you need to do each of the following to get it to work properly:
1. Put the event meta tag above the dispatching class
[Event(name="foo",type="pkg.events.Constants")]
class SomethingThatDispatchesFoo extends EventDispatcher {
Be sure not to accidentally put it on top of the constructor.
2. Make sure the type corresponds to the event class
AS3 gives you the handy CTRL+click functionality on the type string. Unfortunately, it doesn’t autoupdate it during a normal refactor.
If you don’t do this, AS3 will autocomplete it but only as a string.
3. Use double quotes everywhere
The [Event] metatag won’t work at all with single quotes. Also, in code, if you define your string constant with single quotes, constant resolution will not work.
class Constants {
public static const FOO:String = 'foo';
}
// autocomplete will suggest 'foo'
You must use double quotes.
class Constants {
public static const FOO:String = "foo"
}
// autocomplete will suggest Constants.FOO
Some things that you don’t have to do for it to work
- Your event constant name in code (e.g.,
pkg.events.Constants.FOO) does not have to bear any resemblance to the string value it references. You can havepublic static const FOO = "bar"and it will work just great. - It doesn’t appear that you need to recompile to have FB pick up on the new constants.