Archive for December, 2006

A Little ActionScript 3 Reflection

Posted: December 29, 2006 in Flex

During the development of the latest Flex 2 application I came upon nice and powerful ActionScript function. It’s the describeType function. What does it do? It returns an XML object that describes all the instance properties of the supplied parameter. You can pass in any ActionScript value, type, object instances, primitive types, and class objects. So, here a little example:

You can view the example and source here.

Note: Until I figure out how to style my code segments within WordPress (they strip many of my styles out) I will present each code segment without line numbers. Sorry.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx=""
	layout="absolute" width="100%" height="100%"
	pageTitle="describeType Function Demo">

I think by now you know the pupose of the code segment above.

			import flash.utils.describeType;

We start our script tag by importing two classes. The flash.utils.describeType class gives us access to the descibeType function. The class allows us to pass and inspect the event object created when the user clicks on the dataGrid row.

			public var myProperties:XMLList;

Next we declare a XMLList type variable that will be used to hold the XML returned from the call to describeType.

			public function getMyProperties(event:MouseEvent):void {
				myProperties = describeType(imgPhoto)..accessor;

OK, here we go. We define a function that will be called when the user clicks on the image. This function passes a reference to the image to the describeType function. Because the describeType function returns an XML object we then use E4X syntax to access the accessor nodes. Those nodes are then stored as a XMLList in the myProperties variable.

			public function getPropertyValue(event:Event):void {
				var myAccessType:String =;
				var myPropertyName:String =;

				if(myAccessType != "writeonly") {
					if (imgPhoto[myPropertyName] != null) {
						taValue.text = imgPhoto[myPropertyName].toString();
					} else {
						taValue.text = "null";
				} else {
					taValue.text = "Sorry, this property has writeonly rights";

Now this function defines what happens when the user clicks on a dataGrid row. We inspect the selectedItem in the event object to get the value of the access and name attributes. We then check to see if the value of myAccessType does not equal “writeonly”. Then we check to see if the properties value is not null. We do this by accessing the selected Property Name as an array element in the imgPhoto class. The variable myPropertyName will be evaluated for its value. So if everything so far is true, then we get the property’s value and convert it to a string and pass it into out TextArea. We then account for the possibility of a null value and then a property with “writeonly’ access rights.

	<mx:HBox width="100%" height="100%" paddingTop="10" paddingRight="10" paddingBottom="10" paddingLeft="10" horizontalAlign="center">
		<mx:Panel id="myPanel" width="50%" title="My Properties"
			paddingTop="5" paddingRight="5" paddingBottom="5" paddingLeft="5" horizontalAlign="center">

			<mx:Label text="1) Click on the photo to see what it is." fontWeight="bold"/>

			<mx:Image id="imgPhoto" source="18J_11.jpg"
				width="120" height="136" toolTip="What am I?"

			<mx:Label text="2) Click on a property to see its value." fontWeight="bold"/>

			<mx:DataGrid id="dgProperties" dataProvider="{myProperties}" width="100%" change="getPropertyValue(event)">
					<mx:DataGridColumn headerText="Property Name" dataField="@name"/>
					<mx:DataGridColumn headerText="Access Rights" dataField="@access"/>
					<mx:DataGridColumn headerText="Data Type" dataField="@type"/>

			<mx:Label text="Property Value:"/>

			<mx:TextArea id="taValue" width="100%" height="50"/>


OK. Here is our interface. I won’t go into much detail about this code segment. The part I want to concentrate on is the dataGrid. We define a dataGrid cotaining three columns. The first column, Property Name, displays the name of the property by accessing the “name” attribute within the current XML node. The second column displays the property’s Access Rights. The third column displays the property’s Data Type. As you can see, the dataProvider is bound to the myProvider XMLList declared and populated earlier. When the dataGrid’s selection has changed we call our getPropertyValue function.

So there it is. The describeType function returns an XML object containing a wealth of information. You can visit the Adobe Flex 2 Language Reference to get more details.


Flipping Flags Using SQL

Posted: December 22, 2006 in ColdFusion, SQL

Have you ever wanted change the values in your database table from “on” to “off” or “true” to “false” using one compact SQL Statement? Well I did and thus began my journey …

As a long time ColdFusion developer I can remember times when I was presented with the following requirement;

I have a page that displays the results of a DB query. Those results are displayed in a table showing several columns. One of the columns contain a checkbox which, is used by the user to select one or more rows to be activated or deactivated. The user should be able to check one or more rows and click on a button that will execute a process to reverse the flag values for the rows selected. Each checkbox contains the value of the ID of its row.

Now, in the past I may have approached this solution by placing a SQL SELECT and UPDATE statement inside a CFQUERY inside a loop. If the user selected 10 rows then the process would hit the database twice for each row selected – once to get (SELECT … WHERE …) the current value of my flag column and then again to change (UPDATE … SET …) the value based on the value returned from the SELECT statement. It worked but boy was it so very inefficient.

Well, that was NOT going to be the case this time (case … heh … remember that now). So, I set about looking for my own “Holy Grail” (OK smarty … remember, one guy’s simple solution may be another guy’s … you get the point). I enlisted the help of a co-worker of mine (JoAnn) and Voila! she found it. So without further adu, I present to you … the solution:


UPDATE  tblMyTable
SET     tblMyTable.ActiveBit =
        CASE    tblMyTable.ActiveBit WHEN 1 THEN 0 ELSE 1 END
WHERE   tblMyTable.ID IN (#CBSelections#)

So what’s happening here? We used a CASE statement in our SQL query to determine if the value of ActiveBit (a Bit data type column) is 1. WHEN the column value equals 1 THEN we set the column to 0 ELSE we set the column value to 1 – the END


The WHERE clause restricts our UPDATE only to those rows that have ID that are IN the CBSelections list. Selected checkboxes will return a list of its values separated by commas.

Dynamic Tabs in Flex

Posted: December 21, 2006 in Flex

Question: “How do I dynamically add tabs to my TabNavigator?”

Solution: The TabNavigator (and many other controls) support the addChild and addChildTo methods which, allow you to add child controls and components.

Take a look at the sample code segments I’ve posted here:


Communicating with the TileWindow

Posted: December 19, 2006 in Flex

Communicating with the TileWindow

Fortunately, Flex gives us the ability to open and manipulate windows containing additional controls and data. So someone asked me this question:

Question: “How do I create a window in a Flex application and pass data into it?”

Solution: Well the answer is quite simple. Three things are needed to create and open a window within a Flex application; import the TitleWindow class, import the PopupManager class, and create a custom MXML component based on the TitleWindow class. Once you have created an instance of your custom TileWindow, you can then pass a reference to the main application into your TileWindow instance. You can even pass a reference to a data structure into your TileWindow.

In the next few code segments I will explain the application I created to demonstrate this solution.


Survey Says!

Posted: December 19, 2006 in Adobe, ColdFusion

If you ever wondered if ColdFusion still has a strong position in the marketplace, banish the thought. Take a look at this page to see a partial list of Fortune 100 companies that currently use ColdFusion. Maybe you heard of them – FAO Schwartz, Pepsi, Sprint, and more.

World’s Top Companies Use ColdFusion MX

“The grass is greener on OUR side of the fence!”

BAM! The Flex Cookbook Beta is Live!

Posted: December 19, 2006 in Adobe, Flex

In case you haven’t heard, Abobe in partnership with O’Reilly created The Flex CookBook (now in Beta) web site. This new site will become a great resource to find soutions to your Flex related questions, publish your oun solutions, and possibly get a chance to have your solution published in a book bu O’Reilly.

It has already drawn the attention and submissions of some of the better known developer in our community, such as; Andrew Trice, Mike Morearty, and a couple from yours truly (seetherush).

I plan to visit this site often and hope to see many more posts being added in the near future.

It’s Maptacular In Apollo!

Posted: December 19, 2006 in Adobe, Apollo, Flex

Take a look at this fantactic video where Chritian Cantrell shows a couple of really nice Apollo apps. One sample application called Maptacular features a mash-up between Google Maps and his desktopn vCards (address book).

Click on the following to view –

Imagine the possibilities!