PDA

View Full Version : Javascript method not supported ...


stathis30_2000
12-17-2006, 01:41 PM
Hi all !

I am trying to use the 'replace' method of javascript. I get the following error :

call to undefined method 'replace'

Why is that happening ? Isn't javascript fully supported ?


Thanks
ST

caclark
12-18-2006, 11:00 AM
take a look at http://www.laszlosystems.com/lps-3.2/docs/guide/ecmascript-and-lzx.html and you'll see what classes and methods are supported and which aren't.

notzippy
12-18-2006, 12:42 PM
You can use "split" & "join" in conjunction to support a replace...

stathis30_2000
12-18-2006, 11:45 PM
Thank you very much for your replies!

I found the source code of a replace method so I used it. It works fine :-)


ST

pcawdron
02-15-2007, 03:32 AM
Could you post your source code for "replace" ?

Cheers,
Peter

notzippy
02-15-2007, 04:36 AM
"somestring".split("s").join("a")

Confused_Cheese
02-15-2007, 04:56 AM
Could you post your source code for "replace" ?

Cheers,
Peter

Not tried this, but if you want a nice callable function:


function replace(s, t, u) {
/*
** Replace a token in a string
** s string to be processed
** t token to be found and removed
** u token to be inserted
** returns new String
*/
i = s.indexOf(t);
r = "";
if (i == -1) return s;
r += s.substring(0,i) + u;
if ( i + t.length < s.length)
r += replace(s.substring(i + t.length, s.length), t, u);
return r;
}

stathis30_2000
02-15-2007, 06:06 AM
my method for replace is :

<method name="replace" args="input,from,to">
<![CDATA[
var output='';
while(input.length >= from.length && input.length > 0 && from.length > 0){
if(input.substring(0,from.length) == from){
output += to;
input = input.substring(from.length);
}else{
output += input.substring(0,1);
input = input.substring(1);
}
}
return output + input;
]]>
</method>


it works fine !

I am sorry for answering so late but I had not seen your reply!

ST

pcawdron
02-15-2007, 12:31 PM
Thanks... I'm trying out the various approaches now :)

spdzone78
03-29-2007, 11:47 AM
r += replace(s.substring(i + t.length, s.length), t, u);


See above... you can't call the replace function because it is not supported.

Jerinaw
07-31-2008, 10:36 AM
So i guess regular expressions aren't supported either...

senshi
08-03-2008, 06:52 AM
swf8 doesn't support RegExp natively. Adobe added this feature in swf9.