Introduction to Flex — Presentation at Web on the Piste

This morning I gave a presentation on “Introduction to Flex” at Web on the Piste at Queenstown, New Zealand.

It went off quite well — at least that is what I hear from the response to the presentation.

I realized that for an hour-long presentation about 20 slides is the maximum, especially when one is going to show code as well.

I’m attaching a PDF of the presentationwith this blog entry.

Also, I demoed a small RSS reader application based on Flex docs. Here is the code for that.

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

   <mx:HTTPService id="blogService" url="{blogURI.text}" />

   <mx:Panel x="10" y="10" width="624" height="441" layout="absolute" id="blogPanel" title="{blogService.lastResult.rss.channel.title}">

      <mx:DataGrid x="10" y="40" id="blogDatagrid" width="584" dataProvider="{blogService.lastResult.rss.channel.item}" fontSize="14" height="174">

         <mx:columns>

            <mx:DataGridColumn headerText="Title" dataField="title"/>

            <mx:DataGridColumn headerText="Date" dataField="pubDate"/>

         </mx:columns>

      </mx:DataGrid>

      <mx:TextArea x="10" y="225" width="584" height="176" id="blogTextarea" fontSize="14" htmlText="{blogDatagrid.selectedItem.description}"/>

      <mx:TextInput x="10" y="10" width="466" id="blogURI">

         <mx:text>http://syndication.apn.co.nz/rss/nzhrsscid_000000002.xml</mx:text>

      </mx:TextInput>

      <mx:Button x="492" y="10" label="Get RSS Feed" click="blogService.send()"/>

   </mx:Panel>

</mx:Application>

Decision Operators in ColdFusion 8

ColdFusion 8 introduced a few new decision operators.

== (is the same as EQ)

!= (is the same as NEQ)

> (is the same as GT)

< (is the same as LT)

>= (is the same as GTE)

<= (is the same as LTE)

Note that these are available only when used in expressions inside a CFScript block. And they are NOT available in expressions inside CF tags.

<cfscript>
iNum1 = 10;
iNum2 = 20;

writeOutput("<p>iNum1 = #iNum1#<br/>iNum2 = #iNum2#</p>");

/* this is same as using the EQ operator */
bResult = (iNum1 == iNum2);
writeOutput("<p>Is iNum1 equal to iNum2 (iNum1 == iNum2): #bResult#</p>");

/* this is same as using the NEQ operator */
bResult = (iNum1 != iNum2);
writeOutput("<p>Is iNum1 not equal to iNum2 (iNum1 != iNum2): #bResult#</p>");

/* this is same as using the GT operator */
bResult = (iNum1 > iNum2);
writeOutput("<p>Is iNum1 greater than iNum2 (iNum1 > iNum2): #bResult#</p>");

/* this is same as using the LT operator */
bResult = (iNum1 < iNum2);
writeOutput("<p>Is iNum1 less than iNum2 (iNum1 < iNum2): #bResult#</p>");

/* this is same as using the GTE operator */
bResult = (iNum1 >= iNum2);
writeOutput("<p>Is iNum1 greater than or equal to iNum1: (iNum1 >= iNum2): #bResult#</p>");

/* this is same as using the LTE operator */
bResult = (iNum1 <= iNum2);

writeOutput("<p>Is iNum1 less than or equal to iNum1: (iNum1 >= iNum2): #bResult#</p>");
</cfscript>

The code above produces this output.

=======Start output=======

iNum1 = 10
iNum2 = 20

Is iNum1 equal to iNum2 (iNum1 == iNum2): NO

Is iNum1 not equal to iNum2 (iNum1 != iNum2): YES

Is iNum1 greater than iNum2 (iNum1 > iNum2): NO

Is iNum1 less than iNum2 (iNum1 < iNum2): YES

Is iNum1 greater than or equal to iNum1: (iNum1 >= iNum2): NO

Is iNum1 less than or equal to iNum1: (iNum1 >= iNum2): YES

=======End output=======

More information on these can be found in the Adobe Livedocs. Note: Please also have a look at the discussion comments at the bottom of the the related blog entry Boolean Operators in ColdFusion 8.

Searching ColdFusion 8 documentation

The documentation that ships with ColdFusion 8 does not include the functionality to search — unlike ColdFusion documentation in the earlier versions which included a search.

I find that I use the documentation search quite a lot. Livedocs provides the ability to search CF 8 documentation. However, I do not necessarily want to go to the web each time I want to search.

A much nicer way to search ColdFusion 8 documentation is by using Eclipse. Here’s how…

Download CF 8 documentation for Eclipse. And then copy the JAR file into the “plugins” directory of Eclipse. Restart your Eclipse.

Go to Help > Help Contents. You should see “ColdFusion 8 Documentation” appearing in the Contents pane on the left. (If you don’t then something is wrong and you need to sort this out first.)

In the Search box on the top of the Contents pane, type in a keyword, e.g., “cfinterface”. Eclipse indexes the newly added CF Docs and shows the results.

Gotta love Eclipse.

BTW, if you use Flex Builder, you should be able to follow the same process to make CF 8 docs searchable.

String Operators in ColdFusion 8: & and &=

ColdFusion already supports string concatenation using “&” operator.

ColdFusion 8 introduces a new string operator “&=” for compound concatenation.

<cfset sFirstName = "Indy">
<cfset sLastName = "Nagpal">
<cfset spacer = " ">

<cfoutput>
variables.sFirstName = #sFirstName#<br/>
variables.sLastName = #sLastName#<br/>
variables.spacer = " "
</cfoutput>

<!--- & Concatenates strings --->
<cfset variables.sFullName = variables.sFirstName & spacer & variables.sLastName>

<p><strong>Concatanation using &</strong></p>
<p><cfoutput>#variables.sFullName#</cfoutput></p>

<!--- &= Compound concatenation. The variable on the right is used as both an element in the concatenation operation and the result variable. Thus, the expression a &= b is equivalent to a = a & b.
An expression can have only one compound assignment operator.
--->
<cfset variables.sFullName = variables.sFirstName>
<cfset variables.sFullName &= spacer>
<cfset variables.sFullName &= variables.sLastName>

<p><strong>Concatanation using &=</strong></p>
<cfoutput>#variables.sFullName#</cfoutput>

This code yields the following output.

=======Start output=======

variables.sFirstName = Indy
variables.sLastName = Nagpal
variables.spacer = ” “

Concatanation using &

Indy Nagpal

Concatanation using &=

Indy Nagpal

=======End output=======

More information on string operators in ColdFusion 8 is at Adobe ColdFusion 8 Livedocs

Boolean operators in ColdFusion 8: NOT, AND, OR

In ColdFusion 8 one can use shortcuts to refer to three boolean operators: NOT, AND, OR

NOT can also be used to as !

AND can also be used as &&

OR can also be used as ||

<cfset x = 10>
<cfset y = 30>

<cfoutput>
x = #x#<br/>
y = #y#
</cfoutput>

<!--- Reverse the value of an argument. For example, NOT True is False and vice versa. --->
<p><strong>Using NOT or !:</strong> Testing for !x eq y </p>
<cfif !x eq y>
x is not equal to y
<cfelse>
x is equal to y
</cfif>

<p><strong>Using AND or &&</strong>: Testing for x eq 10 && y eq 30</p>
<!--- Return True if both arguments are True; return False otherwise. For example, True AND True is True, but True AND False is False. --->
<cfif x eq 10 && y eq 30>
x is equal to y
<cfelse>
x is not equal to y
</cfif>

<p><strong>Using OR or ||</strong>: Testing for x eq 10 || y eq 20</p>
<!--- Return True if any of the arguments is True; return False otherwise. For example, True OR False is True, but False OR False is False. --->
<cfif x eq 10 || y eq 20>
One of the values is true
<cfelse>
None of the values are true
</cfif>

This code yields the following output.

=======Start output=======
x = 10
y = 30

Using NOT or !: Testing for !x eq y

x is not equal to y

Using AND or &&: Testing for x eq 10 && y eq 30

x is equal to y

Using OR or ||: Testing for x eq 10 || y eq 20

One of the values is true

=======End output=======

The other boolean operators — XOR, EQV, IMP — continue to work as before.
More information on boolean operators in ColdFusion 8 is at Adobe ColdFusion 8 Livedocs.