Featured Posts

Adobe Flex - Filter XML Data using E4X and RegExp Have you ever you wanted to filter your data like you would using the SQL LIKE condition? Well with E4X and RegExp you too can reap the benefits of pattern matching! Here...

Readmore

Flex Assets/File Manager – ASP VBScript - Version... I recently built a JavaScript file manager but I wanted more control and better usability instead of expanding on the JavaScript version I decided to build it using Flex....

Readmore

Getting at your SQL Database using Flex and .NET Web ServicesGetting at your SQL Database using Flex and .NET Web... So you gave up on trying to figure out how you can directly connect Flex to your database like with any server side language and decided to Google the answer. Well by now...

Readmore

Adobe Flex - Filter XML Data using E4X and RegExp Have you ever you wanted to filter your data like you would using the SQL LIKE condition? Well with E4X and RegExp you too can reap the benefits of pattern matching! Here...

Readmore

Fitchett Rss

Flex / Flash Builder – Inline Conditional, If Then, Code

Posted on : 02-11-2009 | By : Michael Fitchett | In : ActionScript, Flash Builder, Flex

0

inline-condition-example-ssInline conditionals, coding, if then’s whatever you want to call it is soooo easy yet has been a pain in the royal _ _ _ for me to find maybe its the search terms I have been Google’ing I don’t know.


Here is a very simple example of how to use an inline conditional to show/hide a button if a check box is selected (checked).

Flex Inline Condition Example

The button has a visible property with the value set to a conditional statement that says if the check box is selected then show the button if it is not then hide the button by setting the value true or false.

visible="{(cbShowButton.selected == true) ? true : false}"

If this is your first time looking at an inline condition here is an image I have put together to explain in a little more detail and help you digest it a little easier

Flex / Flash Builder Inline Condition Example

Flex / Flash Builder Inline Condition Example

The “?” is what ends the condition and the “:” acts as an else.

Yes, there are several ways of showing and hiding a button based on another components value. However I find this way to work out really well because you dont need to preset the button’s visible property to false before running the application. It detects that the check box is not selected at run time and hides the button. Of course you could just pass the check box selected value which is true or false anways but some or most cases you wont be checking againts a true or false value.

Inline conditions really shine when used with data grids. For example so you have a list of people attending an event and you want to show male or female by an icon you can easily accomplish this using an inline condition to check and see if the datagrid column value is male or female and set the image source to to the appropriate path.

<mx:Image source="{(data.colGender == 'male') ? 'assets/male.png' : 'assets/female.png'}"/>

We can also add to this condition by using a comma for example:

<mx:Image source="{(data.colGender == 'male', data.colAge > 21) ? 'assets/male.png' : 'assets/female.png'}"/>

Download Flex inline conditional example project here: Flex Inline Condition - Example Project (43)

http://www.fitchett.me/wp-content/plugins/sociofluid/images/digg_32.png http://www.fitchett.me/wp-content/plugins/sociofluid/images/delicious_32.png http://www.fitchett.me/wp-content/plugins/sociofluid/images/technorati_32.png http://www.fitchett.me/wp-content/plugins/sociofluid/images/google_32.png http://www.fitchett.me/wp-content/plugins/sociofluid/images/myspace_32.png http://www.fitchett.me/wp-content/plugins/sociofluid/images/facebook_32.png http://www.fitchett.me/wp-content/plugins/sociofluid/images/twitter_32.png

Write a comment

Spam Protection by WP-SpamFree

Advertise Here