Weekend Interactive

While my weekend highlight was definitely not the paranoia-inducing documentary about Lyme Disease, I did manage to have a little fun with programming.  Yes, that’s what I said, I had fun programming over the weekend.   Weird, huh?

Luke finished his camp on Friday night, and so of course after running to Dairy Queen for treats to both celebrate that and as a going away event for Dani, we got to see the demo debut of Luke’s ‘Darth Maul Training’ video game.  He had constructed his Darth Maul as the main character and animated him running as he moved.  The first opponents were a mass of ‘training dummies’ that shot splinters at him.  He had to dodge the splinters and use his force lightning to destroy the dummies.  If you made it past the first level, (power-ups included) you faced the ultimate training dummy, whose splinters could take a whole ‘heart point’.  It was a cute game.  Unfortunately though, on the first go round it appears that Luke’s graphic for the big boss wasn’t the right one so he was a little upset, and had to recreate it.  This of course inspired him to want to make bigger and better games, which then led to Saturday taking on Blender and it’s 3D rendering and game engine.  You don’t need a whole lot of programming experience to do the most basic stuff, the physics engine takes care of most of the object interaction, you just have to add a few little events (sensors, controllers, and actuators).  So we  built a little rolly ball game on Saturday before he went over to a friend’s house.

But to improve on my interactive programming here at work, I had a goal to learn a little more about Flash ActionScript.  I determined that Flash is really a pain to work with to get data back and forth between standard programs and databases and Flash itself.  It appears that in the new version of actionscript they’ve taken out or changed all of the code that is used to talk to outside programs, such as coldfusion, and replaced it with code that is more cumbersome to work with.  Previous versions you could set up an object similar to how we set up objects in coldfusion, and then could call the function within the object like a regular function, but not any more in Flash’s AS3.   I’m guessing they’re pushing the new Flex/AIR programming over using Flash, but maybe that’s just me.  Maybe that would be a smarter step to take than trying to learn Flash programming.  After what seemed like countless web searches for example code, I finally put together a little function that could chat with a Coldfusion CFC that returned a query, and I could output the query results.  Of course Actionscript 3 no longer has a recordset datatype either, so I had to convert to an associative array.  Now I just have to learn how to hook into the Coldfusion session so I can use functions wrapped in CFC’s that are in password protected areas.

import flash.net.*; //Required for all the netConnection classesvar myService:NetConnection = new NetConnection(); //set up new netconnection
myService.objectEncoding = ObjectEncoding.AMF0;
myService.connect(http://ourserver.com/flashservices/gateway/); //set up the service
var responder:Responder = new Responder(onResult, onFault); //onResult is a function that gets whatever is returned from the service call
//make the call to the cfc file. You can add a structure of params as the third element in the call. In this case we have none
myService.call("cfc.HelloWorld.showmyquery",responder);

function onResult(re:Object):void
{
/*
//The information returned in the re resulting object in this case contains the serverInfo structure,
//which holds all we need to know about the query
trace(“Total Count: ” + re.serverInfo.totalCount);
trace(“Cursor: ” + re.serverInfo.cursor);
trace(“Service Name: ” + re.serverInfo.serviceName);

trace(“version: ” + re.serverInfo.version);
trace(“RS ID: ” + re.serverInfo.id);
trace(“Initial Data: ” +re.serverInfo.initialData);
*/
trace(“Column Names: ” +re.serverInfo.columnNames);
//We then pull the data we got back from the coldfusion CFC into an associative array
// associative arrays are easier for me to work with than indexed just because you can use the
// column names as a field name, rather than having to remember which is which number.
var rsArr:Array = new Array();
var colCount:Number = re.serverInfo.columnNames.length;
for (var row:Number = 0; row < re.serverInfo.initialData.length; row++) {
rsArr[row] = new Array();
for (var colIndex:* in re.serverInfo.columnNames) {
rsArr[row][re.serverInfo.columnNames[colIndex]] = re.serverInfo.initialData[row][colIndex];
}
}
//loop and output the array just so we know we got the info correctly
for (var i:Number = 0; i < rsArr.length; i++) {
trace(rsArr[i]["dnsServerid"]);
trace(rsArr[i]["dnsServerName"]);
trace(rsArr[i]["dnsServerURL"]);
trace(rsArr[i]["dnsServerIP"]);
trace(rsArr[i]["default"]);
}

}
function onFault(fault:Object):void
{
trace(“Error: ” + fault.description);
}