5 Replies Latest reply on Jan 17, 2008 8:38 AM by Puma1

    Can't duplicate movieclips as an array within an array

    Puma1
      Hello.
      I have an animation that loads an xml into it and traces back an array within an array. I have tried to apply this to duplicated movieclips thereby creating a structured set of links. What I am trying to do is this:

      Chicken Nuggets
      __Compression
      __Texture
      __Disgust
      Mega Warhead
      __Taste
      __Hardness
      __Pain

      This traces fine but I can't seem to get the duplicated movieclips to assemble in this fashion.
      The code for the XML is as follows:

      var controlArray:Array;
      var variable:Array;
      var testTopic = new Array ();
      var test = new Array ();

      var controlsXML:XML = new XML();
      controlsXML.ignoreWhite = true;

      controlsXML.onLoad = function(success:Boolean){
      if (success){
      var mainnode:XMLNode = controlsXML.firstChild;
      var controlNodes:Array = controlsXML.firstChild.firstChild.firstChild.firstChild.childNodes;

      var list:Array = new Array();
      for (var i:Number = 0; i < controlNodes.length; i++) {
      var personnode:XMLNode = controlNodes .attributes.Name;
      trace(personnode);
      testTopic.push (new struct (personnode));
      var specificNode:Array = controlNodes
      .childNodes;
      for (var j:Number = 0; j < specificNode.length; j++){
      var itemnode:XMLNode = specificNode[j].attributes.Variable;
      trace(itemnode);
      test.push (new struct2 (itemnode));
      }


      }
      printer ();
      printer2 ();
      } else {
      trace('error reading XML');
      }
      };
      controlsXML.load ("controls3.xml");

      The code for the movieclip duplication is as follows:

      x = 50;

      function printer ()
      {
      for (m = 0; m < testTopic.length; m++)
      {
      duplicateMovieClip ( slotTopic, "slotTopic" + m, m );
      slotTopic = eval ( "slotTopic" + m );
      slotTopic._y += x;
      slotTopic.slotTopicContent.text = testTopic[m].personnode;
      }
      }

      function printer2 ()
      {
      for (k = 0; k < test.length; k++)
      {
      duplicateMovieClip ( slot, "slot" + k, k );
      slot = eval ( "slot" + k );
      slot._y += x;
      slot.slotContent.text = test[k].itemnode;
      }
      }

      function struct (personnode)
      {
      this.personnode = personnode;
      }

      function struct2 (itemnode)
      {
      this.itemnode = itemnode;
      }

      On the stage are two movieclips, titled "slotTopic" and "slot". Within those are dynamic text boxes titled respectively "slotTopicContent" and "slotContent". When I preview this file it only displays the text within the "slot" movieclip and it lists all six of the subtopics with no break. So, there are two dilemmas:

      1) The movieclips won't duplicate into the structured set of links that I want.
      2) "slotTopic" is not displaying text at all.

      If anyone has any advice, I'd really appreciate it. Thx!
        • 1. Re: Can't duplicate movieclips as an array within an array
          Puma1 Level 1
          Oh, forgot the Xml file code:
          • 2. Re: Can't duplicate movieclips as an array within an array
            Puma1 Level 1
            And here is a better posting of the code:




            • 3. Re: Can't duplicate movieclips as an array within an array
              clbeech Level 3
              ok, I'm sorry but there are quite a few things wrong here. first though, when posting code please use the 'attach code' button.

              1) i can't imagine that you have a XML structure as deep as your calling to or the need for it with the limited amount of infomation your pulling, in addition your storing the info in attributes, so I can't see how this would work, it may 'trace' out the right text (somehow) but it's not getting into the arrays properly.

              2) you do not assign an attribute value to a XMLNode, and then try to push it into an array.

              3) you do not call a method (struct or struct2) using the 'new' operator. this is how you envoke a new 'class' instance.

              4) do not use 'x' as a variable name as it is a reserved var in flash, assigned to an Object instance.

              5) the duplicateMovieClip() method needs to be called upon the existing clip as in:

              slotTopic.duplicateMovieClip('slotTopic'+m, m);

              additionally you can pass the _y placement within the initObject.

              6) you do not need to use eval, it isn't doing anything here, you will gain the correct path by calling duplicateMovieClip correctly.

              7) the reason why slotTopic is not being displayed at all is because of the second loop, you are duplicating the clips (incorrectly) into the same depths thereby replacing all of the contents of the slotTopic depths previously constructed.

              the solution to this problem is to construct both items with the same loop but increament one of the depth assignments by a specific number, in other words at depths much higher or at least different, than that of the first element, as in:

              slotTopic.duplicateMovieClip('slotTopic'+m, m, {_y:50});
              slot.duplicateMovieClip('slot'+(m+100), m+100, {_y:50});

              again I'm sorry man, but it will take some work to sort this out.
              • 4. Re: Can't duplicate movieclips as an array within an array
                Puma1 Level 1
                Yeah, I know the xml structure is crazy, but there is actually a reason for it's depth. This is only one part of a greater app that uses the xml file. Thanks for the advice, I will go through it and see if I can apply it to the animation.
                • 5. Re: Can't duplicate movieclips as an array within an array
                  Puma1 Level 1
                  Decided to gut what I was attempting and try something simpler based on the last advice.
                  However I am still running into problems:

                  I'm trying to setup a horizontal categorical menu drawn from an xml file.

                  I want this:
                  0
                  mainMenuSmall0.jpg
                  1
                  mainMenuSmall1.jpg
                  2
                  mainMenuSmall2.jpg

                  ...etc.

                  The code is attached. 'Slot' and 'Slot2' are what the movieclips (blue and green) that should contain the menu item text as a Dynamic Text box.
                  You can view the .xml file and what I get when I publish here:

                  http://www.itctrng.com/Screenshot.jpg
                  http://www.itctrng.com/dbase.xml

                  Essentially the movieclips are not positioning correctly and only one of each menu item is displaying.

                  Any advice would be much appreciated.

                  Thanks!