I would like to do something like :
mystr = “pr1:10, pr2:44”;
myobj = new object("{" + mystr + “}”);
This syntax doesn’t work.
(I would like not to use this syntax :
myobj.pr1=10;
myobj.pr2=44;)
Thanks for your help.
2c
I would like to do something like :
mystr = “pr1:10, pr2:44”;
myobj = new object("{" + mystr + “}”);
This syntax doesn’t work.
(I would like not to use this syntax :
myobj.pr1=10;
myobj.pr2=44;)
Thanks for your help.
2c
take a look at
http://proto.layer51.com/d.aspx?f=734
might be something to try out.
Otherwise, there is no inbuilt method to do what you’re trying to do. A method for interpreting that string would have to be developed from scratch (much like sx’s example in that link)
how about decode?
Object.prototype.decode = LoadVars.prototype.decode;
var myObj = new Object();
myObj.decode("pr1=10&pr2=44&");
trace(myObj.pr1);
trace(myObj.pr2);
=)
note that decode will make all the variables strings
yeah, i know that. but as far as i know flash doesn’t care if it’s a string/number/whatever. so if flash doesn’t care about that, why would we!?
dec might
:stunned:
good answer.
S and K :
I went to proto.layer.51 before and found nothing.
I think I can use decode (good “astuce” (trick)) and deal with numbers with thinks like isNan(number(myvar)).
Thanks a lot for saving me time.
(I’m writing from France where it’s about 1 pm. Because you’re writing from Mexico and Maryland, I’m amazed you’re so soon in front of your computer ! Did you even went to bed last night ?)
2c
you’re welcome. =)
(and no, i didn’t sleep last night. :P)
Object.prototype.$decode = LoadVars.prototype.decode;
Object.prototype.decode = function(str) {
var obj = new Object();
obj.$decode(str);
for (var prop in obj) {
this[prop] = isNaN(obj[prop]) ? obj[prop] : parseInt(obj[prop]);
}
};
var myObj = new Object();
myObj.decode("pr1=10&pr2=dec&");
trace(typeof myObj.pr1+" "+myObj.pr1);
trace(typeof myObj.pr2+" "+myObj.pr2);
only strings and numbers are recognized, does that help at all? :-\
It works fine.
Because I’m dealing with strings and numbers (not only integers), I’ve just to replace parseInt() by number().
Thank’s again. Have a nice day.
ok. no problem. =)
:: Copyright KIRUPA 2024 //--