views:

26

answers:

2

For instance in Flex 4

?xml version="1.0"?> xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:s="library://ns.adobe.com/flex/spark">

<s:layout> 
    <s:VerticalLayout/> 
</s:layout>

<fx:Script>
    <![CDATA[
        private function setLabel():void {

            trace ("the id is "+myButton.id);
            myButton.id = "yourButton";

        }

    ]]>
</fx:Script>

<s:Button id="myButton" label="Click Me" click="setLabel();"/>

the traces when the button is clicked twice are 'the id is myButton' followed by 'the id is yourButton'

Not just an idle query. I was hoping to change the id of custom components when populating a main app with them

A: 

I would assume that the id of the when set in mxml is the variable name which also sets the internal id (myButton.id = "myButton") Therefore you're able to change myButton.id to "yourButton" because id and variable name are different properties.

Weird one though I'll admit.

If you were to want to create custom components when populating your main app I would look in to a different approach than laying them all out in mxml. Perhaps creating the components in actionscript and setting them in mxml would be best? ( eg your main class is the mxml app and then you have a class behind that does the heavy lifting of creating the view, with all your custom named components )

Karl Freeman
A: 
Beau Scott