Archive for ActionScript2.0

Trim function in AS2.0

This function of trim let you trim spaces from both the end (Start as well as end)…

function trim (txt_str) {
while (txt_str.charAt(0) == ” “) {
txt_str = txt_str.substring(1, txt_str.length);
}
while (txt_str.charAt(txt_str.length-1) == ” “) {
txt_str = txt_str.substring(0, txt_str.length-1);
}
return txt_str;
}

Handling Special Characters

Sending or receiving special characters through URL or loading through xml file………

Let say a string contains characters like ‘éíóúýÂÃØøå’ and you want ro send it as a parameter in the URL to let say a jsp page..

var str:String =”éíóúýÂÃØøå”;

my_loadVar.load(“somejsppage.jsp?name=” + str);  In this case the str value recevied will not be well format so for that hadling these characters you need to encode the URL and that can be done ……

my_loadVar.load(“somejsppage.jsp?name=” + escape(str));  By using escape() function provided by flash we can able to encode it and in the similar way to decode these kind of variable we can use unscape(str)..

escape and unescape take parametera as a string .

Reserved Keywords in Context menu(cut,copy….) in Flash

Using Reserved keywords (cut , copy , paste delete ) in context menu of flash is does not allowed there we have to use something like a dot or three dots etc… as

var my_cm:ContextMenu = new ContextMenu();
var menuItem_cmi:ContextMenuItem = new ContextMenuItem(”Cut”, cutNode);

If u use this then nothing will be displayed in the context menu so…..

var menuItem_cmi:ContextMenuItem = new ContextMenuItem(”Cut…”, cutNode);

you have to give “Cut…” or anything except space …..

If you want to show your contextmenu Cut only then the trick is here..

var menuItem_cmi:ContextMenuItem = new ContextMenuItem(”Cut ”, cutNode);

There is a space after cut but thats not from space key its graphical space for doing that

type Cut+ctrl+2+5+5 i.e after Cut press control key and press 2 5 5 from num pad you are done now……

Trim in AS2.0

These function lTrim, rTrim and Trim let you  use the trim functionality in Flash…….

ltrim trims from left side, rTrim from right side and trim from both end..

// parameters:
// str, string to be trimmed
// returns:- string, whitespaces removed from left side.

function lTrim(str) {
if ((str.length>1) || (str.length == 1 && str.charCodeAt(0)>32 && str.charCodeAt(0)<255)) {
i = 0;
while (i<str.length && (str.charCodeAt(i)<=32 || str.charCodeAt(i)>=255)) {
i++;
}
str = str.substring(i);
} else {
str = “”;
}
return str;
}

// parameters:
// str, string to be trimmed
// returns:- string, whitespaces removed from right side.

function rTrim(str) {
if ((str.length>1) || (str.length == 1 && str.charCodeAt(0)>32 && str.charCodeAt(0)<255)) {
i = str.length-1;
while (i>=0 && (str.charCodeAt(i)<=32 || str.charCodeAt(i)>=255)) {
i–;
}
str = str.substring(0, i+1);
} else {
str = “”;
}
return str;
}

// parameters:
// str, string to be trimmed
// returns:- string, whitespaces removed from both sides.

function Trim(str) {
return lTrim(rTrim(str));
}