Flex 3 gives us a great new feature, custom metadata tags. Now, I know you could actually use custom metadata in Flex 2, but you would have to add “-keep-as3-metadata MyTag” to every single project that utilized these custom tags. In Flex 3, if you add “-keep-as3-metadata MyTag” to a library (using compc to compile a SWC or a Flex Builder Library project), then EVERY project that uses that SWC will automatically keep the “MyTag” metadata tags. This allows custom libraries that utilize these tags for development.
Would be cool to create a library to hook up listeners so you can create listeners like this:
[Listen(obj="this.closeButton", event="click")]
public function closeClickHandler(event:MouseEvent) {...}
You’d use -keep-as3-metadata Listen in the libraries compiler options. Maybe if you want I could post a tutorial on doing something like this. Drop me note and let me know if there is interest.
April 14th, 2008 at 12:55 am
i really want to know how to define metadata tags and how to use them. it’s better to provide me a tutorial.
thanks a lot~
June 7th, 2008 at 12:01 am
Hi, nice blog, will be cool if you publish this tutorial
September 26th, 2008 at 4:20 pm
I worked with metadata lately. There’s a trap in Your idea. You won’t se a compiler error if there’s no this.closeButton object or ‘click’ event.
It’s not much more code in
this.closeButton.addEventListener(MouseEvent.CLICK, closeClockHandler);
and everything is checked in compile time, and I use constant, not string value for event name.
October 15th, 2008 at 11:44 pm
Very true. There’s trade-offs to using metadata for sure.
October 17th, 2008 at 7:53 am
AS3 Metadata tags is one of those topics a few people write about, but nobody goes all the way. They invariably mention the -keep-as3-metadata option, and invariably punt when it comes to showing how to use it in action. It drives me bonkers because I love Java annotations and .NET attributes and would like somebody to provide some concrete comparisons between them. Annotations/attributes are powerful features which make all kinds of interesting things possible at runtime, like ORM mapping tools and a host of dynamic code generation schemes–but I get the impression that metadata tags are not very useful at runtime in AS3, that they are more compile-time features. In any case, yes, PLEASE write the tutorial!
November 13th, 2008 at 12:36 pm
Jacob, I am new to Flex and my background if from .NET. I found interesting the information regarding custom metadata tags. Could you please send me a tutorial if possible.
I would like to know if there is the posibility to associate that metadata tag to a concrete object by the compiler, or if I will have to used “describeType” to dehydrate the concretes at runtime. what are the alternatives
Thanks,
Youd
April 2nd, 2009 at 9:51 am
[...] this blog entry for a little info on how to do custom [...]
September 4th, 2009 at 5:05 am
Could you please explain detail about custom metadata tage usage?
I look for the approach urgent
September 4th, 2009 at 10:31 pm
I don’t have time right now for a full tutorial on using custom metadata. I’ll work on one at some point. But if you use “-keep-as3-metadata Listen” in your Flex Library Project’s properties under “Additional Compiler Options” then when you have a class with the metadata [Listen(arg="value")] above it, or above a method or property, you can see that metadata in the XML of the flash.utils.describeType method.
You can get more information here:
http://www.dreaminginflash.com/2008/01/26/metaprogramming-actionscript3-metadata-in-flex-builder-3/
and here:
http://coenraets.org/blog/2007/10/annotating-actionscript-classes-with-custom-metadata-simple-orm-framework-for-air/
February 17th, 2010 at 1:41 am
Nice blog. It would be helpful if you tell more detail about “-keep-as3-metadata MyTag” and the process to add it in lib. Awaiting your response.
April 26th, 2010 at 7:59 am
Wow! Almost like .Net. :)
This feature could be very useful, thanks.
July 2nd, 2010 at 1:55 am
Awesome
August 10th, 2010 at 7:25 am
[...] 1. Since Flex3, any application that uses a SWC compiled with “-keep-as3-metadata” will not have the metadata specified by the SWC stripped out by the Flex compiler [Reference] [...]
October 29th, 2010 at 10:25 pm
3 easy steps for custom Metadata:
http://cookbooks.adobe.com/post_Custom_metadata_in_three_simple_steps_-11907.html