Skip to main content
Inspiring
April 7, 2009
Answered

Nesting MovieClips

  • April 7, 2009
  • 1 reply
  • 1283 views

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

This topic has been closed for replies.
Correct answer kglad

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?


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

1 reply

kglad
Community Expert
Community Expert
April 7, 2009

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

GumpsterFAuthor
Inspiring
April 7, 2009

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

kglad
Community Expert
Community Expert
April 8, 2009

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.