10 Replies Latest reply on Apr 9, 2009 11:22 AM by GumpsterF

    Nesting MovieClips

    GumpsterF Level 1

      Hello once again folks. The fun never ends eh?

      I am trying to nest some XML fed dynamic text fields converted into MovieClips and exported to actionscript via linkage to appear in another movieclip that I want to use as a holder or mask so that I may scroll through several of these movieclips. Each MoveClip has two dynamic text fields in it, one that displays the price and another that displays the description. For example, MovieClip "itemClip_2_mc" contains both "price2_txt" and "description2_txt" text fields. "itemClip_2_mc" has beenexported to Actionscript via linkage as "itemClip_2_mc".

      If I put all five movieClips onto the stage and give them all instance names and add the instance name to the front of the loaded function, all five load just great.

       

      But when I create an empty movieclip, put it on the stage and give it an instance name of empty_mc, it will not load the itemClip_2_mc from the library, or if it is loading it is not displaying the XML text. What am I doing wrong?

       

      Is there a component that would work better for this?

       

      Here is my XML file (paradise.xml);

       

       

      <?xml version="1.0" encoding="UTF-8"?>
      <copy>
           <item>
                <price>$599.00</price>
                <description>Jamacian Holiday. Come stay at out 5 star resory by the sea. All inclusive!</description>
           </item>
           <item>
                <price>$1,299.00</price>
                <description>Bermuda Holiday. Come stay at out 4 star resory by the sea. All inclusive!</description>
           </item>
           <item>
                <price>$2,200.00</price>
                <description>Bahamas Holiday. Come stay at out 2 star resory by the sea. All inclusive!</description>
           </item>
           <item>
                <price>$3,300.00</price>
                <description>Greek Holiday. Come stay at out 1 star resory by the sea. All inclusive!</description>
           </item>
           <item>
                <price>$5,500.00</price>
                <description>Spanish Holiday. Come stay at out 0 star resory by the sea. Nothing included!</description>
           </item>          
      </copy>
      

       

      Here is my actionscript;

       

       

      function loadXML(loaded) {
           if (loaded) {
                var price = this.firstChild.childNodes[0].childNodes[0].firstChild.nodeValue;
                var desc = this.firstChild.childNodes[0].childNodes[1].firstChild.nodeValue;
                price_txt.text = price;
                description_txt.text = desc;
                var price2 = this.firstChild.childNodes[1].childNodes[0].firstChild.nodeValue;
                var desc2 = this.firstChild.childNodes[1].childNodes[1].firstChild.nodeValue;
                price2_txt.text = price2;
                description2_txt.text = desc2;
                var price3 = this.firstChild.childNodes[2].childNodes[0].firstChild.nodeValue;
                var desc3 = this.firstChild.childNodes[2].childNodes[1].firstChild.nodeValue;
                price3_txt.text = price3;
                description3_txt.text = desc3;
                var price4 = this.firstChild.childNodes[3].childNodes[0].firstChild.nodeValue;
                var desc4 = this.firstChild.childNodes[3].childNodes[1].firstChild.nodeValue;
                price4_txt.text = price4;
                description4_txt.text = desc4;
                var price5 = this.firstChild.childNodes[4].childNodes[0].firstChild.nodeValue;
                var desc5 = this.firstChild.childNodes[4].childNodes[1].firstChild.nodeValue;
                price5_txt.text = price5;
                description5_txt.text = desc5;
           } else {
                content = "file not loaded!";
           }
      }
      
      
      empty_mc.attachMovie("itemClip_2_mc", "newName", 1);
      
      xmlData = new XML();
      xmlData.ignoreWhite = true;
      xmlData.onLoad = loadXML;
      xmlData.load("paradise.xml");
      

       

      help!  :)

      Forrest

        • 1. Re: Nesting MovieClips
          kglad Adobe Community Professional & MVP

          you have more than one problem but to start you'll need more than one movieclip to display all that text.  so, you should be attaching 5 movieclips.

           

          then you need to use the correct path/name reference to the 10 textfields.  that will look something like:

           

          empty_mc.newName0.price_txt.text = whatever;

          empty_mc.newName0.description_txt.text = whateverelse;

           

          etc

          • 2. Re: Nesting MovieClips
            GumpsterF Level 1

            Hi kglad. Nice to hear from you again.

            Yes, I realize I need to attach 5 movieClips.

            Let me try to explain a little better...

            I have five MovieClips in my library, itemClip_1_mc, itemClip_2_mc, itemClip_3_mc, etc.

            each MovieClip contains two dynamic text fields; (price_txt, description_txt) for itemClip_1_mc, (price2_txt, description2_txt) for itemClip_2_mc, etc.

             

            I have exported each MovieClip using Linkage to actionscript (using the same name as the clip).

             

            What I want to do is load them all into an empty movieClip on the stage which I can then attach a UIScrollBar to, so I can scroll through a bunch of them. The dynamic text fields are populated from an XML file.

             

            my code;

             

            empty_mc.attachMovie("itemClip_2_mc", "newName", 1); 
             
            
            

            was my attempt to attach one of my MovieClips into the MovieClip (empty_mc) that is on the stage. "newName" seems to be some code you need to add in AS2 to load a MovieClip from the Library into another MovieClip on the stage. It has worked for me many times with images et al. I guess it is not Loading the XML through all the layers. I would love to attach the files, but I cannot.

             

            Forrest

            • 3. Re: Nesting MovieClips
              kglad Adobe Community Professional & MVP

              first, there's no reason to name those textfields differently.   it will make your coding messier to name they all differently but it won't cause any insurmountable problem.

               

              second, unless those movieclips look different, you could use just one to create your 5 new movieclips.

               

              third, that middle parameter in attachMovie() is the name of your newly instantiated movieclip.  so, that needs to be different for each movieclip attached to the same parent if you want to use actionscript to control any of the movieclips (and you do).

               

              so, with your code use something like:

               

              if(loaded){

              empty_mc.attachMovie(itemClip_1,"mc1",1);
              empty_mc.mc1.price_txt.text = xxx;
              empty_mc.mc1.description_txt.text = xxx;

              empty_mc.attachMovie(itemClip_1,"mc2",2);
              empty_mc.mc2.price2_txt.text = xxx;
              empty_mc.mc2.description2_txt.text = xxx;

              etc

               

              vs:

               

              empty_mc.attachMovie("itemClip","mc1",1);

              empty_mc.mc1.price_txt.text  = xxx;

              empty_mc.mc1.description_txt.text = xxx;

               

              empty_mc.attachMovie("itemClip","mc2",2);

              empty_mc.mc2.price_txt.text = xxx;

              empty_mc.mc2.description_txt.text = xxx;

               

              etc

               

              the biggest benefit of the latter approach is that it's easier to code all that in one for-loop.  you code can be executed in a for-loop too, but it's messier.

              • 4. Re: Nesting MovieClips
                GumpsterF Level 1

                kglad you are indeed a very good teacher. That was a question that has been dooging me for a year. Thank you.

                 

                I know what you are talking about as far as capturing the incoming XML nodes in an array via a loop, but I want to understand this longhand before I try to go there.

                 

                I have two more questions on the same topic if you don't mind..

                 

                When I add each new instance to the empty_mc, the newest replaces what had been loaded before.

                if (loaded) {
                          var price = this.firstChild.childNodes[0].childNodes[0].firstChild.nodeValue;
                          var desc = this.firstChild.childNodes[0].childNodes[1].firstChild.nodeValue;
                          empty_mc.attachMovie("itemClip","mc1",1);
                          empty_mc.mc1.price_txt.text = price;
                          empty_mc.mc1.description_txt.text = desc;
                          var price2 = this.firstChild.childNodes[1].childNodes[0].firstChild.nodeValue;
                          var desc2 = this.firstChild.childNodes[1].childNodes[1].firstChild.nodeValue;
                          empty_mc.attachMovie("itemClip","mc2",1);
                          empty_mc.mc2.price_txt.text = price2;
                          empty_mc.mc2.description_txt.text = desc2;
                

                So "mc2" replaces "mc1" in the empty_mc.

                 

                I want to add "mc2" after "mc1"  followed by "mc3" etc. Would I do something like?......

                 

                          empty_mc.attachMovie("itemClip","mc1"+"mc2"+"mc3",1);
                
                 
                

                 

                I was wondering if you could tell me how I can add a UIScrollbar to the right side of this empty_mc once I get all these mc's to load?

                • 5. Re: Nesting MovieClips
                  GumpsterF Level 1

                  kglad, I wonder if I should be using a component for this rather than an empty movieClip and then trying to attach a UIScrollbar. Perhaps the ScrollPane?

                  I have never used this component, but maybe this is the ticket?

                  Gumpster

                  • 6. Re: Nesting MovieClips
                    kglad Adobe Community Professional & MVP

                    i wouldn't recommend the scrollpane or uiscrollbar for this unless all of the following apply:

                     

                    1.  you're not picky about the way your scrollbar appears.

                    2.  you're not trying to do anything those components don't typically do.

                    3.  you don't mind sacrificing understanding for timeliness.

                     

                     

                    and to answer your question about attaching more than one movieclip to empty_mc, you need to update that depth parameter.  at most, one object can exist at any given depth.  so, if you keep adding movieclips at depth 1 to empty-mc, only the last one added will exist.  the others will have been replaced before anything visible is detected on-stage.

                    • 7. Re: Nesting MovieClips
                      GumpsterF Level 1

                      OK, I understand. So if those conditions don't apply, what would you recommend? My own scrollbar.as code (that I don't have for as2)?

                       

                      If those conditions do apply and say I have a scrollPlane instance on stage called scrollBabyYeah, and I wanted to add these XML laden movieClips to it, how is that done? Like this?.....

                       

                                      scrollBabyYeah.attachMovie("itemClip","mc1",1);
                                scrollBabyYeah.mc1.price_txt.text = price;
                                scrollBabyYeah.mc1.description_txt.text = desc;
                      

                      As to the multiple movieClip loading. I changed each instance to......

                                empty_mc.attachMovie("itemClip","mc1",1);
                      
                                empty_mc.attachMovie("itemClip","mc2",11);
                      
                                empty_mc.attachMovie("itemClip","mc3",21);
                      

                      but they just load one on top of another. I am guessing there must be a way to set the .x and the .y coordinates within the empty_mc when loading each item. Where does that code go in this case?

                      • 8. Re: Nesting MovieClips
                        GumpsterF Level 1

                        Just so you know I am trying here kglad, I changed my code to...

                        if (loaded) {
                                  var price = this.firstChild.childNodes[0].childNodes[0].firstChild.nodeValue;
                                  var desc = this.firstChild.childNodes[0].childNodes[1].firstChild.nodeValue;
                                  trace(price);
                                  trace(desc);
                                  empty_mc.attachMovie("itemClip","mc1",1);
                                  empty_mc.mc1.price_txt.text = price;
                                  empty_mc.mc1.description_txt.text = desc;
                                  empty_mc.mc1._x = 0;
                                  empty_mc.mc1._y = -75;
                                  
                                  var price2 = this.firstChild.childNodes[1].childNodes[0].firstChild.nodeValue;
                                  var desc2 = this.firstChild.childNodes[1].childNodes[1].firstChild.nodeValue;
                                  trace(price2);
                                  trace(desc2);
                                  empty_mc.attachMovie("itemClip","mc2",11);
                                  empty_mc.mc2.price_txt.text = price2;
                                  empty_mc.mc2.description_txt.text = desc2;
                                  empty_mc.mc2._x = 0;
                                  empty_mc.mc2._y = 0;
                                  
                                  var price3 = this.firstChild.childNodes[2].childNodes[0].firstChild.nodeValue;
                                  var desc3 = this.firstChild.childNodes[2].childNodes[1].firstChild.nodeValue;
                                  trace(price3);
                                  trace(desc3);
                                  empty_mc.attachMovie("itemClip","mc3",21);
                                  empty_mc.mc3.price_txt.text = price3;
                                  empty_mc.mc3.description_txt.text = desc3;
                                  empty_mc.mc3._x = 0;
                                  empty_mc.mc3._y = 100;
                                  
                                  var price4 = this.firstChild.childNodes[3].childNodes[0].firstChild.nodeValue;
                                  var desc4 = this.firstChild.childNodes[3].childNodes[1].firstChild.nodeValue;
                                  trace(price4);
                                  trace(desc4);
                                  empty_mc.attachMovie("itemClip","mc4",31);
                                  empty_mc.mc4.price_txt.text = price4;
                                  empty_mc.mc4.description_txt.text = desc4;
                                  empty_mc.mc4._x = 0;
                                  empty_mc.mc4._y = 200;
                        

                        Now this did place each instance apart from one another vertically ok, but they do not seemed to be constrained by the empty_mc.

                        • 9. Re: Nesting MovieClips
                          kglad Adobe Community Professional & MVP

                          yes, if those don't apply and you need to scroll empty_mc, you'll be making your own scrollbar and coding it.

                           

                          if you're going to use the scrollpane (say sp),  create an empty movieclip in the authoring environement and give it a linkage id (say emptyID).  then you can use:

                           

                          sp.contentPath = "emptyID";

                           

                          sp.content.attachMovie(xxid,xx,xxdepth);

                          sp.content.attachMovie(yyid,yy,yydepth); // assign _x and/or _y properties of sp.content.yy

                          etc

                           

                          use sp.invalidate() to force sp's scrollbars to adjust to the new content

                          • 10. Re: Nesting MovieClips
                            GumpsterF Level 1

                            Once again you have been an amazing teacher sensei kglad.

                             

                            The scroll plane was just what I was looking for!

                             

                            Thanks!