This ARB issue was revisited on 12/14/2009.
The original proposal was to change the way MXML 2009 handled unqualified id attributes. The original proposal suggested that if a suitable id property existed on the type that the id attribute would also set the property.
This decision was reverted and unqualified id attributes in MXML 2009 will retain the Flex 3 behavior of only functioning as a compile time language attribute. To get access to MXML id information at runtime a type should implement mx.core.IMXMLObject.
<s:Application xmlns:s="library://ns.adobe.com/flex/spark" xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:local="*"> <fx:Declarations> <local:MyComponent id="prop1" /> </fx:Declarations> </s:Application>
The MXML 2009 behavior for qualified attributes still applies, however. An id attribute prefixed with the MXML 2009 language namespace is the same as an unqualified id attribute, i.e. it is seen as an MXML id language attribute.
<local:MyComponent fx:id="prop1" />
An id attribute prefixed with the owning component's namespace is seen as a normal property assignment and will not be seen as an MXML id language attribute.
<local:MyComponent local:id="1234" />
An id attribute in an unknown namespace is seen as application private metadata and is ignored.
<local:MyComponent foo:id="Some value" xmlns:foo="http://designtool/foo" />
The original (but obsolete) proposal is retained below.
h2. Problem Description
In MXML the id attribute is a special attribute. It is used to define the name of a generated property declaration on the underlying ActionScript class and it allows the property to be referenced in script and binding expressions.
However, if a type has an id property the developer may intend the attribute to represent a property assignment and not just as an identifier in MXML.
In Flex 4 we introduced an interface mx.core.IID that the developer must implement to instruct the compiler to generate an id property declaration. However, this requires a dependency on the framework.
Some classes, such as those in the Text Layout library, need the id property at runtime but they cannot depend on the Flex framework. Another scenario where the id property is needed at runtime is to style components using CSS id selectors.
h2. Decision
Option 1.
h2. Decision Criteria
The Advanced CSS code must be able to match components using id selectors at runtime, and the Text Layout library must be able to locate text nodes by id at runtime.
h2. Proposed Solution(s):
h3. Option 1. - Use Type Introspection (Opt-out via Namespaces)
Instead of testing that a type implements the mx.core.IID interface, the compiler instead checks to see if the type has a writable, public, non-static, id property of type String. If present, the compiler process the attribute as a property.
Note: this would only be done for MXML 2009 and later.
<s:MyClass id="123" />
If a suitable property was not found the compiler would simply not generate an id property. The id attribute would only serve as an MXML identifier.
To opt-out of this behavior the developer could prefix the id attribute with the language namespace prefix. The id attribute would only serve as an MXML identifier.
<s:MyClass fx:id="123" />
h3. Option 1b. (Also Opt-out of MXML behavior via Namespaces)
For the sake of completeness we could also consider allowing the developer to opt-out of the MXML identifier logic by prefixing the attribute with the component namespace.
<s:MyClass s:id="123" />
If a suitable property was not found the compiler would generate an id property not found error.
h3. Option 2. - Move Interface Outside of Framework
We simply move the mx.core.IID interface outside of the Flex framework so that it can be used without Flex. It would still require types to opt-in to the id property generation by implementing an interface.
h2. Recommended Solution:
Option 1. or 1b.
h2. Notes:
If we go with option 1, we should have a consistent solution for Application special attributes (frameRate, etc...) and the new states attributes (includeIn, excludeFrom, etc...)