ActionScript URL Encoding/Decoding
Posted By : todd sharp Posted At : January 11, 2007 8:37 AM Posted In: ActionScript, ColdFusion
7
I just had an issue on one of my work sites where a flash form was passing a dynamic data element via the url from a grid to a new page which pulled a report. The problem was that one of the dynamic values contained a "&" which obviously presents a problem. If this was pure CF I could simply use urlEncodedFormat() and urlDecode() to handle this, but since the variable in question is coming from a flash form I wasn't quite sure how to handle this one (Flash gurus can look away now).
A quick Google later, I found that ActionScript has a very similar set of functions called escape() and unescape(). I only needed to use escape() in my case, since the var was being handled by CF on the target page. I did employ the good old urlDecode() on the target page and everything worked out perfectly. Don't you love it when the solution is so simple? It's almost like the folks that make these languages know what they're doing.


Ameen
I chose not to do XML but sendvars and encountered
the same thing. Gonna go check escape() out thanks!
The unescape method in AS 3 has been changed from AS 2. If you want to unescape + (urlencoded whitespace) you have to use the replace method in combination.
var urlencodedString:String = "foo+bar%26param=1";
var badString = unescape(urlencodedString);
var niceString:String = unescape(urlencodedString).replace(/\+/g, " ");
trace(badString) // foo+bar¶m=1
trace(niceString) // foo bar¶m=1
var badString:String = unescape(urlencodedString);
http://livedocs.adobe.com/flash/9.0/ActionScriptLa...()
http://livedocs.adobe.com/flash/9.0/ActionScriptLa...Component()
I could unvail the original html code in flash.