Archive for October, 2008

Regular Expressions in Flex and AS3

16.10.2008 0

I’ve needed to user Regular Expressions a couple of times since they were introduced in ActionScript 3 and invariably find myself trawling the Regular Expression tutorial/example websites out there which in general I find very confusing! I don’t think Regular Expressions are that difficult to grasp (the basic anyway) but none of the example sites I’ve found have clear explanations of the syntax.

I’m currently developing a Crossword Application in Flex for a client which is pretty much complete. However, one of the bugs I had to resolve today was being caused by some unforseen incompatibility issues with the solution text node coming from the client’s huge database of crosswords xml files. If a solution for example had a space, apostrophe, hypen or various other punctionation it needed to be stripped out of the node by my code to ensure that the correct number of cells were generated on my crossword app grid. So here’s an example of using a regular expression to do just that:

var notCharOrNum:RegExp = /[^A-Za-z0-9]/gi;
var myText:String = "The bee’s knees";
myText = myText.replace(notCharOrNum,""); //outputs “Thebeesknees”
trace(myText);

In summary the reg expression means match everything that isn’t either a letter or a number. The ^ bit is the special character than means except these characters. The g means global – I think that just means the match continues searching throughout the string until it reaches the end. The i means case insensitive search so I guess this would do the same thing:

var notCharOrNum:RegExp = /[^a-z0-9]/gi;
var myText:String = "The bee’s knees";
myText = myText.replace(notCharOrNum,""); //outputs “Thebeesknees”
trace(myText);

Yep – just checked and it does!

Flash Player 10 – Official Launch

15.10.2008 0

The official launch of Flash Player 10 went live a couple of hours ago.

I’ve just downloaded and and installed the update and am pleased to find that the debug version is working perfectly with Flex Builder 3’s debugger (see past post for issues last time I updated).

So go ahead and download the update!

Flex RIAs can’t call Google APIs

14.10.2008 2

I’ve been looking into ways to access the Google APIs from Flex recently for an Air Project I’m planning to build in my spare time.

I managed to get the following process working fairly easily in AIR:

Step 1: User enters their Google login details which then get passed to google’s https://www.google.com/accounts/ClientLogin API login script which returns a string of variables including the google session authorization variable.

Step 2: Using the Auth variable passed back from a successful google login you can then call the many Google data APIs available – in the example I built after a successful login the app simply retrieves the user’s google contact list.

This all seemed to be working fine in Adobe AIR.

It was when I tried to port this to a web based RIA that I started running into obstacles.

Most of the problems are down to google’s lack of / restictions in their crossdomain.xml

There’s a crossdomain file here:

http://www.google.com/crossdomain.xml

But it doesn’t include the <allow-access-from domain=”*” /> tag  :-(

Plus there’s no crossdomain.xml file on google secure domain https://www.google.com domain which needs to be called to get the authorization variable to access the various APIs.

Even when you run a Flex app locally in a browser you run into further problems if you ever get past the login stage you then need to send the ‘Authorization’ head with “auth=[the_key]” with every API call in the header of you HTTP request.

But guess what? As of flash player 9.0.115 the “Authorization” header was been blacklisted! So it just gets ripped out of the request and the call to google fails!

From reading other posts I understand that you can now use the Authroization header with more recent versions of Flash Player but…

The site you’re calling requires this to be added to the crossdomain file:

<allow-http-request-headers-from domain="*" headers="Authorization"/>

More info from Adobe here:

http://kb.adobe.com/selfservice/viewContent.do?externalId=kb403184&sliceId=2

No – that node doesn’t not exist in Google’s crossdomain file! Lol.

So, my next attempt to get round this obstacle involved downloading Abdul Qabiz’s as3httpclient library for adding headers to your http requests from Flex.

This actually gets round the header issue very well and did allow me to call Google Contacts API request url and include the required Authorization header. Locally that is…

As soon as I then tried to run the working files on my remote web server I saw that for socket calls too (this is how the as3httpclient make requests) also requires a crossdomain.xml for socket calls :-(

I give up – am just going to stick to building an AIR app where it all just works…

Nokia Headphone Designer site goes live

09.10.2008 0

I can’t claim much involvement in this project apart from a bit of AMFPHP remoting consultancy and optimization but it’s a cool site work taking a look at, Flex side developed by my 2 co-senior Flex Devs – Paddy Keane and Martin McBrearty from my agency – World Archipelago Internet

http://www.nokia.com/headsetdesign

More info on Paddy’s Blog

Corner Radius Doesn’t work on HBox/VBox

06.10.2008 2

I haven’t been responsible for the skinning on most of our Flex projects but today that’s exactly what I’ve been doing all day. I just discovered that setting the cornerRadius style of a HBox or VBox has no effect when used on it’s own in css or MXML. The style ‘borderStyle’ also needs to be set to ’solid’ for the cornerRadius you’ve set to display! Weird…