A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: Please lend me a clue about Shared Objects...

  1. #1
    Member
    Join Date
    May 2002
    Posts
    62
    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

  2. #2
    Senior Member
    Join Date
    Jun 2002
    Posts
    199
    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;

  3. #3
    Senior Member
    Join Date
    Jan 2001
    Posts
    472
    Code:
    category = "food"; 
    aName = "dairy"; 
    bName = "milk"; 
    my_SO = SharedObject.getLocal(category); 
    my_SO.data[aName] = {};
    my_SO.data[aName][bName] = _root.some.text;

  4. #4
    Senior Member
    Join Date
    Jun 2002
    Posts
    199
    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?


  5. #5
    Member
    Join Date
    May 2002
    Posts
    62
    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?

  6. #6
    Senior Member
    Join Date
    Jan 2001
    Posts
    472
    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.


  7. #7
    Senior Member
    Join Date
    Jun 2002
    Posts
    199
    aha,

    thanks!

  8. #8
    Member
    Join Date
    May 2002
    Posts
    62
    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!

  9. #9
    Senior Member
    Join Date
    Jun 2002
    Posts
    199
    sorry I threw you off laurasdog,
    your problem was one I have been having too, I hoped the typo catch would solve it.



  10. #10
    Member
    Join Date
    May 2002
    Posts
    62
    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!

  11. #11
    Member
    Join Date
    May 2002
    Posts
    62
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center