Aug 24, 2005
Or at least I forget them. I have been pulled into a project that is data driven pages built completely in Flash because I know enough actionScript to be useful (this is the reason I have not been posting as much of late). It has reminded me that, when no one is asking me to make animations or design, I actually enjoy Flash (though I hate programming in the Flash IDE and
FDT for Eclipse is too expensive for something I don't do regularly). However, here a couple of silly "gotchas" that got me this past week.1)
ActionScript is case sensitive - This is obvious you say. Well, here is my example, and it probably won't seem so obvious. I built a CFC that returns a single query record at random from a larger query using the
QueryRandomRows UDF available at
CFLib. This worked fine when the Flash was exported for Flash 6, but we needed to export for Flash 7 and suddenly it broke. Well, as you can see, QueryRandomRows uses the query columnlist to recreate the query, and, as you probably know, the columnlist always comes back in all caps (why is this?). So the reason this broke was because Flash saw the fields as all caps (so id became ID). In this particular case, I fixed it be lcase-ing the query column names (since that is how they were in the db anyway), but while the fix was simple it is definitely worth noting (why this worked in Flash 6 and not 7 I am not sure - but I am not overly familiar with the changes between the versions to be honest).
2) Arrays in Flash Start at 0 - This is another fairly obvious one with another case where it was easily overlooked. I had a function that returned an array where the array position was tied to a numeric id (i.e. array position 1 contained data for an item with an ID of 1...I won't go too deep into the details of why I did it that way). Anyway, you can see where this is headed...array position 1 became array position 0 in Flash, so I was looking at the wrong data. In this case, since I build seperate functions specifically for any Flash Remoting (this keeps things clean and allows me to send the bare minimum of data across to help speed up the process), I simply bumped the positions up 1.
I tend to think I am fairly well aware of the rules of Flash as they differ from ColdFusion, and, in fact, I was aware of both these rules but still managed to get caught by them.
Arrays in every programming language are zero-based.
Posted By k. / Posted on 08/24/2005 at 8:41 AM
This is not true in coldFusion. If you need proof try this:
<cfset arr = arrayNew(1)>
<cfset arrayAppend(arr,"hello")>
<cfdump var="#arr#">
Notice it inserts at position 1 for the first element.
<cfset arr = arrayNew(1)>
<cfset arrayInsertAt(arr,0,"hello")>
<cfdump var="#arr#">
This will produce an error.
Posted By Brian Rinaldi / Posted on 08/24/2005 at 9:03 AM
Also, my point was really that the array position shifted down a notch when brought from ColdFusion to ActionScript.
Posted By Brian Rinaldi / Posted on 08/24/2005 at 9:05 AM
If you want CFMX to return case sensitive properties to ActionScript via Flash Remoting, use bracket notation instead of dot notation. Subsequent uses via dot notation is fine, but defining the property needs to use bracket notation to keep case sensitivity.
eg.
....
<cfset var result = StructNew()>
<cfset result["errorMsg"] = "">
<cfset result.ErRoRmSg = "This is my new error message.">
<cfreturn result>
And ActionScript (try the NetConnection Debugger) will see:
result.errorMsg: "This is my new error message."
AS2 is case sensitive. AS1 is not. Hence your F6 ActionScript didn't care, but you're probably compiling to AS2 for your F7 projects.
Cheers,
- Ian
Posted By Ian Chia / Posted on 08/24/2005 at 9:42 AM
Now come on it isn't that bad Brian... I look at it almost the opposite way that you do. I go from Flash and look at ColdFusion and say, why don't they do this more like actionscript. I have to get back to work now... I am working late here with Flash, I don't get to use ColdFusion anymore with my new job.
Posted By Jeff Fall / Posted on 08/24/2005 at 6:46 PM