Error: Id attribute is not allowed on the root tag of a component
I have a code like the one below
<mx:Button id="TestingID" width="100%" height="20">
<mx:Script>
<![CDATA[
import flexlib.containers.WindowShade;
]]>
</mx:Script-->
</mx:Button>
I am getting the error "id attribute is not allowed on the ro开发者_开发技巧ot tag of a component"
I have to give a Id to the button to refer to it. What should i do.. how do i solve this problem??
Regards Zeeshan
if you are calling the component from within itself then you use the 'this' keyword.
<mx:Button height="20">
<mx:Script>
<![CDATA[
import flexlib.containers.WindowShade;
this.percentWidth = 100;
]]>
</mx:Script-->
</mx:Button>
And if you want to refer to the custom component from your application then you do this.
<application xmlns:local = "[Directory containing custom component]">
<local:MyCustomButton id="myButtonInstantiation" />
</application>
Make sense?
An MXML file is essentially a class. So if you want to reference the instance of that class from within it then you just use "this".
This can also happen if you are nesting a component inside another
As soon as you use the <fx:Component>
tag you are in the root of an mxml-inline-document
<mx:itemEditor>
<fx:Component>
<mx:TextInput id="precioVenta"/>
</fx:Component>
</mx:itemEditor>
All you need to do is move the id
attribute into the tag like this
<mx:itemEditor>
<fx:Component id="precioVenta">
<mx:TextInput />
</fx:Component>
</mx:itemEditor>
This applies to any kind of tag or nesting that causes the Flex compiler to create a new context for the inlinde declaration of a component
If you're defining this in a file as a subclass of Button
then you can't set the id
here. Put the id in the place you use this new component. For example, if this new component will be an AwesomeButton
, you could use it like so:
<mycompnamespace:AwesomeButton id="testingId" />
Let see below code -
<s:ComboBox id="myCombo" dataProvider="{al}">
<s:itemRenderer>
<fx:Component>
<s:CheckBox **id="NOWAY**" click="clickHandler(event)"/>
</fx:Component>
</s:itemRenderer>
</s:ComboBox>
id is not allowed in these sort of scenarios, you use of 'this' keyword, because in this context CheckBox is root tag within Component.
精彩评论