Setting Properties

Using the <mx:SetProperty> tag you can set the property value for any component existing within the state. For example, you can set the text for a label, toggle the enabled property for a text input, change the x and y coordinates for a box, or even apply a filter, such as a blur effect. The <mx:SetProperty> tag requires target, name, and value attributes. The target attribute value needs to be a reference to the object to which you want to apply the new property value. The name attribute lets you specify the name of the property you want to set. The value attribute allows you to specify the value you want to assign to the property. Example 12-8 uses two buttons to toggle between the base state and a state that enables a text input.

Example 12-8. Setting properties

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

    <mx:HBox id="hbox">
        <mx:Button id="enableButton" label="Enable"
            click="currentState='enabled';" />
        <mx:Button id="disableButton" label="Disable" click="currentState='';" />
        <mx:TextInput id="textinput" enabled="false" text="example text" />
    </mx:HBox>

    <mx:states>
        <mx:State name="enabled">
            <mx:SetProperty target="{textinput}" name="enabled" value="{true}" />
        </mx:State>
    </mx:states>

</mx:Application>
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset