-
Greetings,
I'm trying to figure out how to name shared objects dynamically...
I can make this work:
catagory="food";
my_SO = SharedObject.getLocal(catagory);
my_SO.data.dairy.milk= _root.some.text;
But I want to be able to assign the whole name dynamically something like this:
catagory="food";
aName="dairy";
bName="milk";
my_SO = SharedObject.getLocal(catagory);
my_SO.data[aName + "." + bname]= _root.some.text;
except that doesn't work...
Can anyone lend me a clue?
Thanks
-
typo in here,
catagory="food";
aName="dairy";
bName="milk";
my_SO = SharedObject.getLocal(catagory);
// lowercase n in bname, try uppercase.
my_SO.data[aName + "." + bname]= _root.some.text;
-
Code:
category = "food";
aName = "dairy";
bName = "milk";
my_SO = SharedObject.getLocal(category);
my_SO.data[aName] = {};
my_SO.data[aName][bName] = _root.some.text;
-
tyard,
I am still coming to grips with this type of eval,
I am still using eval() !
I'm so old fashioned.
what is the purpose of this:
my_SO.data[aName] = {};
?
IS it some form of validation?
-
Thanks for the reply, but I'm afraid the typo is irrelevant. That's just a bit of code I used for an example. In the real thing, the variable names come out of an input text box, and I'm very certain everything is spelled right. Everything works good up to:
my_SO.data[aName + "." + bName]= _root.some.text;
But that part fails. I'm certain it's not a typo in the real code. I wish it was that easy... Thanks tho!
Other ideas?
-
persist,
my_SO.data[aName] = {};
is the same as:
my_SO.data[aName] = new Object();
I'm simply creating a new property for the data object called "dairy" (aName) and assigning that property a data type of Object. You need to do this before you create a property for "dairy". Once "dairy" is an object, you can give it the property "milk" and assign milk a value.
-
-
tyard wrote:
Code:
category = "food";
aName = "dairy";
bName = "milk";
my_SO = SharedObject.getLocal(category);
my_SO.data[aName] = {};
my_SO.data[aName][bName] = _root.some.text;
Aha! That looks interesting. I'll give that a try first thing in the morning. Thanks very much!
-
sorry I threw you off laurasdog,
your problem was one I have been having too, I hoped the typo catch would solve it.
-
tyard, thanks for the explaination with that.
I've never seen " my_SO.data[aName] = {}; "
as a way to create a new object. Now I've learned 2 cool things from this thread. Thanks guys!
-
follow up...
Thanks again tyard, I did a quick test on the code you posted and it WORKS! Yippeee!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|