Here is a little tool that I have made which can be used to encode and decode strings into URL escape sequences (eg. convert special characters so they are safe to transmit in a query string). I recently also had the need to encode and decode HTML named entity references (eg. ” becomes ”) and after a long hunt around the web I couldn’t find one in AS3. So I have also written a static class called HTMLEntities which has the public methods ‘encode’ and ‘decode’. Hopefully you will find it useful. All the source code is available below.
NOTE: If you use the HTMLEntities class, you may want to remove the entry for the apostrophe (‘) which encodes it as ' because it is not supported by Internet Explorer. Apostrophes are better off being encoded as '
Here are some useful lists of the HTML Named Entities …
Following on from yesterday’s post, I’ve had chance to update the Colour Line Drawing demo to include gradual colour changing (instead of random) and fixed the saving of the image to a jpeg file.
function createJPG(m:MovieClip, q:Number, fileName:String) { var jpgSource:BitmapData = new BitmapData (m.width, m.height);
jpgSource.draw(m); var jpgEncoder:JPGEncoder = new JPGEncoder(q); var jpgStream:ByteArray = jpgEncoder.encode(jpgSource);
var header:URLRequestHeader = new URLRequestHeader ("Content-type", "application/octet-stream");
var jpgURLRequest:URLRequest = new URLRequest ( serverPath+"jpg_encoder_download.php?name=" + fileName + ".jpg");
jpgURLRequest.requestHeaders.push(header);
jpgURLRequest.method = URLRequestMethod.POST;
jpgURLRequest.data = jpgStream;
var jpgURLLoader:URLLoader = new URLLoader();
navigateToURL(jpgURLRequest, "_blank"); }