#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    32
    Rep Power
    7

    Duplicate movie based on array data


    Hello flash enthusiasts,

    I am currently building a (mock up) to view subscriber information by duplicating a movie clip based on an array. I'm grabbing the data from an xml and trying to pass the array to duplicated clips. The problem I'm running into is that I can only get data to the first duplicated movie and the original remains blank.

    Here is the xml:
    Code:
    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <content>	
    	<article>
    		<last4id>1111</last4id>
    		<fnameid>fname1</fnameid>
    		<lnameid>lname1</lnameid>
    		<expdate>11/11</expdate>
    		<addressid>1111 First St</addressid>
    		<cityid>Los Angeles</cityid>
    		<stateid>CA1</stateid>
    		<zipid>11111</zipid>		
    	</article>
    	<article>
    		<last4id>2222</last4id>
    		<fnameid>fname2</fnameid>
    		<lnameid>lname2</lnameid>
    		<expdate>22/22</expdate>
    		<addressid>2222 Second St</addressid>
    		<cityid>San Francisco</cityid>
    		<stateid>CA2</stateid>
    		<zipid>22222</zipid>		
    	</article>
    </content>
    Here is how I'm loading the xml:
    Code:
    function loadXML(loaded) {
    	if (loaded) {
    		xmlNode = this.firstChild;
    		last4id = [];
    		fnameid = [];
    		lnameid = [];
    		expdate = [];
    		addressid = [];
    		cityid = [];
    		stateid = [];
    		zipid = [];
    		total = xmlNode.childNodes.length;
    		for (i=0; i<total; i++) {
    			last4id[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
    			fnameid[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
    			lnameid[i] = xmlNode.childNodes[i].childNodes[2].firstChild.nodeValue;			
    			expdate[i] = xmlNode.childNodes[i].childNodes[3].firstChild.nodeValue;
    			addressid[i] = xmlNode.childNodes[i].childNodes[4].firstChild.nodeValue;
    			cityid[i] = xmlNode.childNodes[i].childNodes[5].firstChild.nodeValue;
    			stateid[i] = xmlNode.childNodes[i].childNodes[6].firstChild.nodeValue;
    			zipid[i] = xmlNode.childNodes[i].childNodes[7].firstChild.nodeValue;
    		}
    		nextFrame();
    	} else {
    		trace("Can not load edit card xml");
    	}
    }
    xmlData = new XML();
    xmlData.ignoreWhite = true;
    xmlData.onLoad = loadXML;
    xmlData.load("edittest.xml");
    And on the next frame I'm running a for loop:
    Code:
    for (i=1; i<total; ++i) {
    	item_mc.info_mc.duplicateMovieClip("info_mc"+i, i);
    	item_mc["info_mc"+i]._y = item_mc["info_mc"+i]._height+15;
    	item_mc["info_mc"+i].fname.text = fnameid[i];
    	item_mc["info_mc"+i].lname.text = lnameid[i];
    	item_mc["info_mc"+i].cdigits.text = last4id[i];
    	item_mc["info_mc"+i].cdate.text = expdate[i];
    	item_mc["info_mc"+i].caddress.text = addressid[i];
    	item_mc["info_mc"+i].ccity.text = cityid[i];
    	item_mc["info_mc"+i].cstate.text = stateid[i];
    	item_mc["info_mc"+i].czip.text = zipid[i];
    }
    I'm wondering if I'm missing an initial load step or that I'm not splitting the array correctly.

    Any and all help is greatly appreciated and thank you for taking a moment to look at this post.

    Thanks,
    Kumba
  2. #2
  3. No Profile Picture
    Gotta get to the next screen..
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2003
    Location
    Legion of Dynamic Discord
    Posts
    6,678
    Rep Power
    3164
    Hi, well the XML side seems alright, make sure you have a stop() on the first frame so it doesn't go straight to the next frame before the XML has loaded.

    The original clip info_mc wouldn't have any data written to it unless you are doing that outside the loop, in code you haven't shown.

    I think the problem is that it is actually duplicating the clip and writing the text but you are not positioning the copies vertically correctly. You're basically putting all of them at the same _y position. Here's an updated copy of the loop:
    Code:
    var item:MovieClip;
    var item_height:Number = item_mc.info_mc._height;
    for (i=0; i<total; ++i)
       {
          if(i == 0)
             item = item_mc.info_mc;
          else
             item = item_mc.info_mc.duplicateMovieClip("info_mc"+i, i);
    	
          item_mc["info_mc"+i]._y = i * (item_height + 15);
          item.fname.text = fnameid[i];
          item.lname.text = lnameid[i];
          item.cdigits.text = last4id[i];
          item.cdate.text = expdate[i];
          item.caddress.text = addressid[i];
          item.ccity.text = cityid[i];
          item.cstate.text = stateid[i];
          item.czip.text = zipid[i];
       }
    stop();
    I changed the loop so it starts at 0 and then added the if statement in so that if it's 0 then it writes the data to the original clip, otherwise it writes it to the duplicate. I used the variable item because array notation for MovieClip access is quite slow so you should use it sparingly. I also fixed the _y position so that it now uses the i increment to properly space things out.
    Quis custodiet ipsos custodes?

IMN logo majestic logo threadwatch logo seochat tools logo