shared object using arrays

  • Buck Nasty
  • Novice
  • Novice
  • User avatar
  • Posts: 21
  • Loc: Philadelphia

Post 3+ Months Ago

Hey guys,
I am trying to send the visible state of a movieclip that is nested in a series of movieclips in an array as a shared object. When I trace it being sent, it seems to record the visiblity of them but when i try to pull the data back in and set the visibility back to those clips it doesnt seem to work. When i trace it i only seem to get the visibility of one of the movieclips. Ill drop the code below if anyone could help me out i would appreciate it. I know i am missing something and i cannot seem to find anything only to help address this problem. I think i just need something else to help repoulate the array but i am not sure what to do. "checkPage" is the movieclip that i want the shared object to store and return visibility states. It is nested inside all of the tocArray mcs.

Code: [ Select ]
//the array i am using
tocArray = [mc0, mc1, mc2, mc3, mc4];

//the function to send the visible states

function bookmarkCourseChecks()
  {
    for(i = 0; i< tocArray.length; i++)
    {
    tocBtnStates1 = tocArray[i];
    user1 = SharedObject.getLocal("user_profile1");
    user1.data.checkMarks = tocBtnStates1.checkPage._visible;
    trace(user1.data.checkMarks);
    }
  }

//the function to pull back in the data (but it doesnt work)

function checkCourseBookmarkChecks()
  {
  user1 = SharedObject.getLocal("user_profile1");
  tocBtnStates1.checkPage = user1.data.checkMarks;
  trace(tocBtnStates1.checkPage);
  }
  1. //the array i am using
  2. tocArray = [mc0, mc1, mc2, mc3, mc4];
  3. //the function to send the visible states
  4. function bookmarkCourseChecks()
  5.   {
  6.     for(i = 0; i< tocArray.length; i++)
  7.     {
  8.     tocBtnStates1 = tocArray[i];
  9.     user1 = SharedObject.getLocal("user_profile1");
  10.     user1.data.checkMarks = tocBtnStates1.checkPage._visible;
  11.     trace(user1.data.checkMarks);
  12.     }
  13.   }
  14. //the function to pull back in the data (but it doesnt work)
  15. function checkCourseBookmarkChecks()
  16.   {
  17.   user1 = SharedObject.getLocal("user_profile1");
  18.   tocBtnStates1.checkPage = user1.data.checkMarks;
  19.   trace(tocBtnStates1.checkPage);
  20.   }
  • krismeister
  • Graduate
  • Graduate
  • krismeister
  • Posts: 202

Post 3+ Months Ago

Your code has 2 problems.

One
The way you have it is the sharedObject gets written to 5 time and each time writes over itself. The following will really store an array in the sharedObject, where as your original code was only storing one true or false value.
Code: [ Select ]
function bookmarkCourseChecks():Void
  {
    var visibleArray:Array = new Array();
        
    for(i = 0; i< tocArray.length; i++)
    {
    visibleArray[i] = tocArray[i].checkPage._visible;
    }
        
        user1 = SharedObject.getLocal("user_profile1");
    user1.data.checkMarks = visibleArray;
    trace(user1.data.checkMarks);
  }
  1. function bookmarkCourseChecks():Void
  2.   {
  3.     var visibleArray:Array = new Array();
  4.         
  5.     for(i = 0; i< tocArray.length; i++)
  6.     {
  7.     visibleArray[i] = tocArray[i].checkPage._visible;
  8.     }
  9.         
  10.         user1 = SharedObject.getLocal("user_profile1");
  11.     user1.data.checkMarks = visibleArray;
  12.     trace(user1.data.checkMarks);
  13.   }

Two
The 2nd issue you are having is variable scope. When you declared tocBtnStates1 in the loop of bookmarkCourseChecks() it got destroyed at the end of the function. By the time you get around to calling checkCourseBookmarkChecks() tocBtnStates1 doesn't exist.

You'll need to make a loop in checkCourseBookmarkChecks() and cycle through each member of checkMarks and assign it's 'true' or 'false' value to the member of the same index in tocArray.
  • Buck Nasty
  • Novice
  • Novice
  • User avatar
  • Posts: 21
  • Loc: Philadelphia

Post 3+ Months Ago

Cool thanks alot for your help. I am going to try that today. I will post back and let u know how it works out. I really appreciate the help.
  • Buck Nasty
  • Novice
  • Novice
  • User avatar
  • Posts: 21
  • Loc: Philadelphia

Post 3+ Months Ago

Thanks again krismeister. I got it to work fine.

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 3 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.