Event metadata: using a static variable for the "name" attribute?

I want to use Event metadata tags to show what types of events will be sent by my controller. The syntax looks like this:

<fx:Metadata> [Event(name="eventName", type="MyEvent")] </fx:Metadata> 

In Flex / Actionscript, it seems to be best to define static variables that define event names like this:

 public class MyEvent extends Event { public static const EVENT_NAME:String = "eventName"; // Other stuff.. } 

This is a good practice, as the event name can be easily changed and should not be changed throughout the code. So my question is: is there a way to use this static const in a metadata event tag? I can not do something like this:

 <fx:Metadata> [Event(name="{MyEvent.EVENT_NAME}", type="MyEvent")] </fx:Metadata> 

I just don’t know the correct syntax to do this, or is it impossible? It seems that he simply asked to find it difficult to find errors if someone decides to change const, since it is not strictly specified here. Thanks in advance!

+7
source share
2 answers

Bad news is impossible :( I dream about this opportunity, but ...

+6
source

Yes, it is impossible to do, but there is nothing that prevents you from performing your check at runtime. metadata can be obtained by calling describeType() in the class (in this case). parse the xml and check the values ​​against your consts. if there is a problem, print an error or print a trace. it's not perfect but it will give you some security

+1
source

All Articles