title: extracting Array data from SharedObject
body: <p>Im having a game where after I finish a certain level I put that level`s name In an Array and save that array to an SharedObject(SO). But somehow/somewhere I mess up things, because after closing and opening the game again, I load the SO data (to unlock the levels that I have passed) and it is (the loaded data)  always messed up and not loading what it should load(sometimes it even trows some errors at me.)</p>
  
  <p>The code is not that difficult but I have been looking at it for far to long and I need new eyes to see the obvious mistakes in it.
  <strong>***********EDIT**********</strong>
  So the code for the SO is this</p>
  
  <pre><code>public class LevelsData extends SharedObject
  {
      public static var LEVELS_DATA:SharedObject = SharedObject.getLocal("save_poi71");
  
      public static function get LoadNamesOfLevelPassed():Array
      {
          var myLevelsArr:Array = [];
          if( LEVELS_DATA.data.PlayedLevels_arr == undefined)
          {
              myLevelsArr.length = 0;
          }
          else
          {
              myLevelsArr = LEVELS_DATA.data.PlayedLevels_arr;
          }
          return myLevelsArr;
      }
      public static function set SaveLevel_Names( nameOfLevelPassed:Array ):void
      {
          LEVELS_DATA.data.PlayedLevels_arr = nameOfLevelPassed;
          LEVELS_DATA.flush();
      }
  }
  </code></pre>
  
  <p>and the code in the game is this</p>
  
  <pre><code>.
  .
  .
  .
  
  
  
  private function didWePlaySameLevel():void
      {
          var namesPlayed_arr:Array = LevelsData.LoadNamesOfLevelPassed;
          var namesTotal:int = namesPlayed_arr.length;
          if( namesTotal == 0 ) 
          { 
              trace("     ScreenInGame_2 | didWePlaySameLevel | namesTotal == 0  so we push Level_1");
              namesPlayed_arr.push( Moving_Picture_Name );  
              LevelsData.SaveLevel_Names = namesPlayed_arr;
              sameLevel = false;
          }
          else if( namesTotal != 0 )
          {
              for( var i:int = 0; i &lt; namesTotal; i++)
              {
                  trace("             ScreenInGame_2 | didWePlaySameLevel | " + Moving_Picture_Name + " ?==? " + namesPlayed_arr[ i ] );
                  trace("             ScreenInGame_2 | didWePlaySameLevel | namesPlayed_arr.length = " + namesPlayed_arr.length);
                  if( Moving_Picture_Name != namesPlayed_arr[ i ]  )
                  {
                      trace("                 ScreenInGame_2 | didWePlaySameLevel | " + Moving_Picture_Name + " != " + namesPlayed_arr[ i ] );
                      namesPlayed_arr.push( Moving_Picture_Name );
                      LevelsData.SaveLevel_Names = namesPlayed_arr;
                      sameLevel = false;
                      trace("                 ScreenInGame_2 | didWePlaySameLevel | namesPlayed_arr.length = " + namesPlayed_arr.length);
                  }
              }
          }
      }
  
  
  .
  .
  .
  if( levelsToUnlock &lt; totalLevels &amp;&amp; sameLevel == false )
  {
      trace("ScreenInGame | unlockOneMoreLevel | we UNLOCK 1 more level" );
      unlockNextLevel();
  }
  </code></pre>
  
  <p>***EDIT PROBLEM:</p>
  
  <p>SomeHow i figured a way of solving my 1st problem, but now there is a new one and that is :</p>
  
  <p>When the Array from the SO is != 0 i go into the <strong>else if</strong> statement. There i compare if any of the variables in the Array have the same name of the <strong>Moving_Picture_Name</strong> and if they dont then I set the <strong>sameLevel = false</strong>. The problem is that, if lets say I have passed/played 5 levels before( Level_1,Level_2,Level_3,Level_4,Level_5 ) and lets say I start playing <strong>Level_2</strong> again it would show me this:</p>
  
  <p>Level_2 != Level_1 - > and it will push itself into the Array and update the data</p>
  
  <p>Level_2 == Level_2 - > it will do nothing</p>
  
  <p>Level_2 != Level_3 - > and it will push itself into the Array and update the data</p>
  
  <p>Level_2 != Level_4 - > and it will push itself into the Array and update the data</p>
  
  <p>Level_2 != Level_5 - > and it will push itself into the Array and update the data</p>
  
  <p>so it will actually push 4 Elements in the Array that exist already in that Array.</p>
  
  <p>***THE QUESTION :</p>
  
  <p>So how do I push the newLevel only if its name isnt in that Array(the one where I save the names), And how do I do nothing if the name exist in the Array already.</p>