ColdFusion, WDDX, and Flash (Page 6 of 8)

THE FLASH SIDE (Continued)

##include "wddx.as"

//function definition that will deserialize the packet and write data to the Flash movie function loaded (valid) { if (valid) { //deserialize the WDDX packet _root.queryResults = _root.converter.deserialize(this); //extract the information we want to display in our movie _root.EmployeeID.text = _root.queryResults.getField(0, "EmployeeID"); _root.FirstName.text = _root.queryResults.getField(0, "FirstName"); _root.LastName.text = _root.queryResults.getField(0, "LastName"); _root.PhoneExtension.text = _root.queryResults.getField(0, "PhoneExtension"); } }

//create an instance of the WDDX class (which is defined in WDDX.as) converter = new WDDX(); myXML = new XML(); myXML.ignoreWhite = true; myXML.onLoad = loaded; myXML.load("http://localhost/wddxTutorial/qry_GetEmployees.cfm");

I've left out the line numbers in the code above so you can easily copy and paste it from this page into your Flash movie. To accomplish this, copy the code above and then go back to Flash. Click on frame 1 of the actions layer and open up the Actions panel. Paste the code at the bottom of the panel. There should be some commented lines of code already on this frames actions. If you see these lines you know you are in the right place. If you see anything else repeat the steps above to be sure you are viewing the actions for frame 1.

The code you just pasted is specific to FlashMX. The only thing you need to do to get the code compatible with Flash5 is to remove the .text syntax from each of the root variables. In FlashMX, text is actually an object whereas in Flash5 it was not. The correct syntax to reference a dynamic text field in FlashMX is _root.yourVariable.text while in Flash5 it was _root.yourVariable.

The first line of code is used to include the wddx.as file. You can open the file in any text editor you wish and take a look at it. Basically, it's the code in the wddx.as file that does all the work in Flash in order to parse the WDDX packet that Flash has read in. There are tons of valuable functions in the wddx.as file but I'll let you work through most of them by yourself. There's really only two that we are going to be concerned with. The deserialize function takes any valid, well-formed WDDX packet and parses it into an object that Flash can use. The getField function returns the element in a given row/column sequence.