Arul's Blog On Multimedia, Flash MX, Director And Dreamweaver MX
Recent Entries | Guest Book | QuickView | XML-RSS feed | My Profile | Home
::: About this Blog :::
Welcome to Arul's Blog!
Weblog on Multimedia,
Macromedia Flash MX Flash MX
Macromedia Director Shockwave Studio 8.51 Director
Macromedia Dreamweaver MX Dreamweaver MX
View my profile And me :)
Here I'm going to share my views, opinions and code with you all.

::: Services :::

:. ActionScript Highlighting
:. AS Highlighter v2 new!


::: ActionScript :::
:. toString
:. skipCache
:. getWords
:. getDateFromString
:. colorUtils
:. XMLNode-transformTags
:. Object-copyProperties
:. Object-clone

::: ActionScript 2 :::
:. XMLHighlighter
:. PriorityQueue

::: Archives :::
[September 2002]
[October 2002]
[November 2002]
[December 2002]
[January 2003]
[February 2003]
[March 2003]
[April 2003]
[May 2003]
[June 2003]
[July 2003]
[September 2003]
[October 2003]
[December 2003]
[January 2004]
[February 2004]
[March 2004]
[April 2004]
[May 2004]
[June 2004]
[July 2004]
[December 2004]
[January 2005]
[February 2005]
[March 2005]
[May 2005]
[June 2005]
[July 2005]
[August 2005]
[June 2006]
[July 2006]
[November 2006]
[December 2006]
[January 2007]

::: Time Zone :::
All Times on this blog are
GMT + 5:30 Hours
(Indian Standard Time)

::: Flash Resources :::
:. Flash Components
:. Were-Here Forum
:. Digital Illusion
:. Flashmove Forum
:. Flash Goddess
:. Prototypes
:. Actionscript Toolbox
:. UltraShock
:. Chattyfig
:. Full as a Goog
:. Flog

::: Flashers :::
:. Mike Chambers
:. Greg Burch
:. Branden Hall
:. Samuel Wan
:. Stuart Schoneveld
:. Guy Watson
:. Robin Debreuil
:. Mario Klingemann
:. Moises
:. Aral Balkan
:. Peter Hall
:. Josh Dura
:. Alessandro
:. Brajeshwar
:. Nik Khilnani

::: Small Print :::

© Copyright 2002
R.Arul Kumaran

[Made with Blogger]


Sunday, March 28, 2004

Code.Flash MX: ActionScript for handling HTML Escape Characters.

In my last post I've explained about Unicode notation handling. Now let's see how we can process HTML escape characters in the &#number; format. This format is used for placing Unicode characters in a plain HTML page (ANSI) without using UTF-8 Encoding With the help of the actionscript below you can create a HTML editor in flash which can pass the escaped string to server side script for saving it as a plain HTML file which properly renders the Unicode characters in the browser.
function setMinimumDigits(num, digits) {
        var str = num.toString();
        while (str.length<digits) {
                str = "0"+str;
        }
        return (str);
}
String.prototype.HTMLUnescape = function() {
        var arr:Array = this.split("&#");
        var l:Number = arr.length;
        while (l--) {
                var s = arr[l];
                arr[l] = String.fromCharCode(parseInt(substring(s, 0, 4)))+substring(s, 6, -1);
        }
        return arr.join("");
};
String.prototype.HTMLEscape = function() {
        var s:String = "";
        for (var i = 0; i<this.length; i++) {
                var d = this.charCodeAt(i);
                if (d<127) {
                        s += this.charAt(i);
                } else {
                        s += "&#"+setMinimumDigits(d, 4)+';';
                }
        }
        return s;
};
Usage:
var test = "??pa??thu??kaa??p??pu";
//encoding
var encoded = test.HTMLEscape();
trace(encoded);
//traces "&#2986;&#3006;pa&#2980;&#3009;thu&#2965;&#3006;kaa&#2986;&#3021;p&#2986;&#3009;pu"
//
//decoding
trace(encoded.HTMLUnescape());
//traces "??pa??thu??kaa??p??pu"

posted by Arul | link | ^top | next> | add comment
Tuesday, March 16, 2004

Code.Flash MX: ActionScript for Unicode Escape Notation handling.

When your back end does not give full support for Unicode ( like PHP, amfphp etc.,) you may use the following function to encode the characters as notations before sending it to server and decode the notations back to the characters before display.

It is the improved version of the code I used in my Unicode escape notations generator. Some people asked me to release the code, so here it is
function setMinimumDigits(num, digits) {
        var str = num.toString();
        while (str.length<digits) {
                str = "0"+str;
        }
        return (str);
}
String.prototype.decodeNotation = function() {
        var arr:Array = this.split("\\u");
        var l:Number = arr.length;
        while (l--) {
                var s = arr[l];
                arr[l] = String.fromCharCode(parseInt(substring(s, 0, 4), 16))+substring(s, 5, -1);
        }
        return arr.join("");
};
String.prototype.encodeNotation = function() {
        var s:String = "";
        for (var i = 0; i<this.length; i++) {
                var d = this.charCodeAt(i);
                var c = this.charAt(i);
                if (d<127) {
                        s += c;
                } else {
                        s += "\\u"+setMinimumDigits(d.toString(16).toUpperCase(), 4);
                }
        }
        return s;
};
Usage:
var test = "பாpaதுthuகாkaaப்pபுpu";
//encoding
var encoded = test.encodeNotation();
trace(encoded);
//traces "\u0BAA\u0BBEpa\u0BA4\u0BC1thu\u0B95\u0BBEkaa\u0BAA\u0BCDp\u0BAA\u0BC1pu"
//
//decoding
trace(encoded.decodeNotation());
//traces "பாpaதுthuகாkaaப்pபுpu"

posted by Arul | link |<prev. | ^top | next> | add comment

footnote:-
Also check the recent entries and feel free to add your comments. I need your comments to improve this blog