tags:

views:

215

answers:

3

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 root 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

A: 

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" />
thenduks
I did not get it... will you plz explain a bit more
Zeeshan Rang
You should consider the book Programming Flex 3 so you can get familiar with the basics of Flex development (http://www.amazon.com/Programming-Flex-Comprehensive-Creating-Applications/dp/0596516215)
thenduks
+1  A: 

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".

James Ward
+2  A: 

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?

Adrian