|
|
[DefaultProperty] defines a default property. [duh] |
They must have been putting in some late nights at Adobe while working on the documentation for Flex… nevertheless, here is an excellent example of how [Not] to write (from Creating and Extending Flex 2 Components).
DefaultProperty metadata tag
The
[DefaultProperty]metadata tag defines the name of the default property of the component when you use the component in an MXML file.The
[DefaultProperty]metadata tag has the following syntax:[DefaultProperty("propertyName")]The propertyName property specifies the name of the default property.You can use the
[DefaultProperty]metadata tag in your ActionScript component to define a single default property. For more information, and an example, see “Creating a default property” on page 125.
[Yawn] If you’ve learned anything about what exactly default properties are from this excerpt can you please explain it to me?
Also, I’d just like to add that the Flex metadata tags, of which there are 11, represent a minor [WTF?] for me. These are used to [Manually] mark certain bits of code as things that the compiler should be aware of but would otherwise not be (for example, all events must be marked with an [Event] metadata tag for Flex to recognize them). It’s probably not as bad as it seems but I wish they had figured out a [BetterTechnique].
Would anyone care to comment on metadata tags?
August 21st, 2006 at 4:01 pm
How useless! I can’t fault them too much, since in general Adobe did a great job of documenting flex. This is definitely one of those exceptions though…
Metadata tags are for when you’re writing stuff in AS3 that you know is going to be used in MXML. Because MXML is eventually compiled down to AS3, this information is not necessary for the actionscript compiler, but it’s good for the flex compiler. That’s why the actionscript compiler is just going to ignore stuff standing alone inside brackets. [IBetItsABadIdea("to add comments this way!")]. But this is actually a particularly good example of things that make sense in MXML and not AS3.
Their example is, that when they coded the Label class they put in a [DefaultProperty("text")]. What the hell is a default property? It’s when your MXML element has a text node as its child. In other words, when you just type inside the MXML tag, that stuff will be assigned to the default property.
<mx:Label>hi</mx:Label>
is the same as
<mx:Label text="hi"/>
is the same as
<mx:Label><mx:text>hi</mx:text></mx:Label>
because “text” is the default property.