Friday, July 30, 2010

Flash updating Twitter Status the easy way, right?

Twitter has a super easy way of updating twitter statuses via URL, but the awesome Wez Crozier and I came across some issues.  But first to how you do this:

var url:String = "";

First note:  do not try, because it will not work.  Your escaped items (mainly Hashtags # == %23) will not be unescaped for you.  Props to Wez for that one.

Here's some awesome RegEx code Wez figured out for me too (I suck at RegEx):

var textToPostToTwitter:String = postText.text;
var input:String = url+textToPostToTwitter;
var output:String = input.replace(new RegExp(/\s/g), "+");
output = output.replace(new RegExp(/\#/g), "%23");

Something that I figured out because I was trying to be lazy and sneaky was that you have to replace the whole String.  I mean you can't just replace the String you want as the status and do a url + input.replace(new RegExp(/\s/g), "+");.  

So, I hope that helps some of you guys not fall into the trap we did.  And thanks again Wez, you rock.

Follow Wez at:

And use Grant Skinner's awesome RegExr.