Shaikh Sonny Aman’s Blog

previously www.mailtoaman.com

Learning Flex3 Task2: First action and accessing component property

Posted on | June 7, 2008 |

Every person has his/her own way of learning. My way is to learn by example. I may understand some math rules but I will be more confident at exam if done some practice example using that theory. Similar to this, I can understand what a language can do by reading but I will be much more comfortable if you do some real codes using that language.

As you are accompanying me in this journey, I will rather emphasis on the code example than on theory. I will try my best to reveal all the strength of flex3 to you by examples.

In this lesson, we will use a button and perform an action when it is clicked.

Let’s see what we would do in html:

<input type=”button” value=”click me” onclick=”this.value=’clicked’” />

Now, this is what we need to do in flex3.

<mx:Button id=”btn1″ label=”click me” click=”{btn1.label=’clicked’}” />

Now, in flex this means the main movie which we can put aside for the moment. For the time being we can think that all UI components must be accessed with their ID.

Here we have seen another feature which is accessing properties of a component.

Besides accessing properties, we can also bind properties. We will use a text box, a label and a button to demonstrate binding components. We will also use a button to clear the text of the two components.

Here is the code:

<?xml version=”1.0″?>

<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml”>

<mx:Panel title=”App 2″>

<mx:TextInput id=”txtName” text=”hello” />

<mx:Button id=”btn1″ label=”Clear All” click=”{lblName.text=”;txtName.text=”}” />

<mx:Label id=”lblName” text=”{txtName.text}”/>

</mx:Panel>

</mx:Application>

We can see that on entering anything in the textbox automatically updates the label text.

Download file: Main.msxml

Prev : Learning Flex3 Task1: IDE and basic application
Start: Start
Next: Learning Flex3 Task 3: Using function in script tag and in separate ActionScript file

Comments

2 Responses to “Learning Flex3 Task2: First action and accessing component property”

  1. Junal Rahman
    June 7th, 2008 @ 10:38 am

    Nice to see your writing after a long time. i also like to understand things with an example :) keep writing ..

  2. Shaikh Sonny Aman
    June 8th, 2008 @ 8:31 pm

    Thanks Junal bhai, I am inspired :)

Leave a Reply