3 Replies Latest reply on Jan 16, 2008 9:28 PM by yenniie

    Problem with Duplicate Movie Clip which is tracked in an Array

    yenniie
      I have a problem with my inventory code using Shared Objects. What i did was to track the collected items in an array. Each time the user collects an item, the original iconMC is duplicated and loads a picture of the item (function loadImage). However, my problem is that this retains the original array so even if I already added new items into the inventory, the newest item doesn't show. original array length = 2, new array length = 3; the last item doesn't show. If I reload my flash, its the only time that this shows. Now if I get an item and lessen the inventory, it still retains the original length and doubles (or triples, depending on how many items i lessened) the last item.

      var so:SharedObject = SharedObject.getLocal("lakbayUser", "/");
      var i:Number = so.data.currentUserIndex;
      var ctr = 0;
      var iconCtr;
      var iconArray: Array; //temporary storage of items placed inside icon

      function selectIcon(num){
      eval("iconMC"+num)._alpha = 0;
      so.data.users [15][0] = true;
      so.data.users
      [15][1] = iconArray
      ;
      }

      //loads the next icon
      function setNextIconMC(itemCtr, iconCtr){
      if(iconCtr > 0) {
      newName = "iconMC" + iconCtr;
      newPos = 130 * iconCtr;
      _root.itemaHolderMC.iconHolderMC.iconMC0.duplicateMovieClip(newName,iconCtr+1);//does not duplcate if unloadMovie is called
      this[newName]._x = newPos;
      this["iconMC"+iconCtr].enabled = true;
      this["iconMC"+iconCtr]._alpha = 100;
      loadMovie("gamit/icon"+itemCtr+".jpg",_root.itemaHolderMC.iconHolderMC[newName]);
      trace(_root.itemaHolderMC.iconHolderMC[newName]);
      }
      else {
      iconMC0.enabled = true;
      iconMC0._alpha = 100;
      loadMovie("gamit/icon"+itemCtr+".jpg",_root.itemaHolderMC.iconHolderMC.iconMC0);
      }
      }

      //loads all the icons into the container
      function loadImage(){
      iconCtr=0;
      iconArray = new Array();
      for(itemCtr = 0; itemCtr < so.data.users [14].length; itemCtr++){
      if(so.data.users
      [14][itemCtr] == true){
      iconArray[iconCtr] = itemCtr;
      setNextIconMC(itemCtr,iconCtr);
      iconCtr++;
      }
      }
      if(iconCtr==0){
      iconMC0._visible = false;
      }
      else iconMC0._visible = true;
      }

      loadImage();
      so.flush();
      stop();