Solved

setting up an array for predefined text field

Posted on 2008-11-03
7
573 Views
Last Modified: 2013-11-11
Hi,

can some one help me how to load a text from xml using array OR for loop method. like how i loaded images into predefined movie clips on stage using this script--var mcs:Array = [mc1,mc2,mc3,mc4,mc5,mc6,mc7,mc8,mc9];//movie clips predefined on stage

actually i wanted to cutdown the script from line 19th to 61 you can take a look at it on code snippet. anyways i have attached the source file which contains the images folder, fla file &  xml file. if some can help me any easier way to get this same thing it would be great.

Thanks
stop();

//var xpos:Number = 0;//the incrementng position of the images

var mcs:Array = [mc1,mc2,mc3,mc4,mc5,mc6,mc7,mc8,mc9];//movieclips predefined on stage

 

 

 

 

//this.firstChild = this.firstChild; 

 

var xmlImages:XML = new XML();//xml document - will load from external file

xmlImages.ignoreWhite = true;//ignores whitespace characters, so it won't ruin the xml structure

xmlImages.load("images.xml");//tell it to load the external xml

 

xmlImages.onLoad = function(ok) {

	if (ok) {//if it loads ok

	

		var images:Array = this.firstChild.childNodes;//get the main <pic> nodes in a array

		

		tittle1 = this.firstChild.childNodes[0].childNodes[1].firstChild.nodeValue;

		desc1 = this.firstChild.childNodes[0].childNodes[2].firstChild.nodeValue;

		link1 = this.firstChild.childNodes[0].childNodes[3].firstChild.nodeValue;

 

 

		tittle2 = this.firstChild.childNodes[1].childNodes[1].firstChild.nodeValue

		desc2 = this.firstChild.childNodes[1].childNodes[2].firstChild.nodeValue

		link2 = this.firstChild.childNodes[1].childNodes[3].firstChild.nodeValue;

 

 

		tittle3 = this.firstChild.childNodes[2].childNodes[1].firstChild.nodeValue

		desc3 = this.firstChild.childNodes[2].childNodes[2].firstChild.nodeValue

		link3 = this.firstChild.childNodes[2].childNodes[3].firstChild.nodeValue;

 

 

		tittle4 = this.firstChild.childNodes[3].childNodes[1].firstChild.nodeValue

		desc4 = this.firstChild.childNodes[3].childNodes[2].firstChild.nodeValue

		link4 = this.firstChild.childNodes[3].childNodes[3].firstChild.nodeValue;

 

 

		tittle5 = this.firstChild.childNodes[4].childNodes[1].firstChild.nodeValue

		desc5 = this.firstChild.childNodes[4].childNodes[2].firstChild.nodeValue

		link5 = this.firstChild.childNodes[4].childNodes[3].firstChild.nodeValue;

 

 

		tittle6 = this.firstChild.childNodes[5].childNodes[1].firstChild.nodeValue

		desc6 = this.firstChild.childNodes[5].childNodes[2].firstChild.nodeValue

		link6 = this.firstChild.childNodes[5].childNodes[3].firstChild.nodeValue;

 

 

		tittle7 = this.firstChild.childNodes[6].childNodes[1].firstChild.nodeValue

		desc7 = this.firstChild.childNodes[6].childNodes[2].firstChild.nodeValue

		link7 = this.firstChild.childNodes[6].childNodes[3].firstChild.nodeValue;

 

 

		tittle8 = this.firstChild.childNodes[7].childNodes[1].firstChild.nodeValue

		desc8 = this.firstChild.childNodes[7].childNodes[2].firstChild.nodeValue

		link8 = this.firstChild.childNodes[7].childNodes[3].firstChild.nodeValue;

 

 

		tittle9 = this.firstChild.childNodes[7].childNodes[1].firstChild.nodeValue

		desc9 = this.firstChild.childNodes[7].childNodes[2].firstChild.nodeValue

		link9 = this.firstChild.childNodes[7].childNodes[3].firstChild.nodeValue;

		

		for (i=0; i<images.length && i < mcs.length; i++) {//iterate through each <pic> node until there are movieclips on stage

			//get the text value of each sub tags of pic

			var img = images[i].childNodes[0].firstChild.nodeValue;//<image>

 

			//var caption = images[i].childNodes[1].firstChild.nodeValue;//<caption>

			//var link = images[i].childNodes[2].firstChild.nodeValue;//<url>

			var mc:MovieClip = mcs[i];//here we get a predefined mc on stage

			mc.createEmptyMovieClip("img",0);

			//mc.link = link; // set its link - in as2 MovieClip is dynamic, so it accepts any runtime property you create

			//mc.caption = caption; // same for caption

			

			/*mc.onPress = function() {

				trace("clicked:"+this.link);

				//set its behavior so when clicked will open the link in new page

				getURL(this.link, "_blank");

			};*/

			mc.img.loadMovie(img);//loads the image

			//updates the x position, so the next image stays on side

			xpos += 60;

		}

 

	} else {

		trace("xml could not be loaded. check file name");

	}

};

Open in new window

Xml-Predefined-content-loder.zip.pdf
0
Comment
Question by:mmucom
  • 3
  • 3
7 Comments
 
LVL 39

Expert Comment

by:blue-genie
ID: 22867791
where exactly is the problem in your file?
the code you uploaded is not the same as your code snippet.
0
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 22868139
I have updated the main FLA,
just download it and rename the extension to .fla

gallery-final.fla.txt
0
 

Author Comment

by:mmucom
ID: 22873878
Hi aneesh,

thanks for your interest i download your file looked at it's good one. but we have one problem with it if u see at my old file i had a invisible button on top of each predefined movie clip. so on each button on release function i set it up in such a way thats need to load a different .XML file in a (gal) frame label. it seems its not possible with the file u sent it so how do we get that working???

Thanks
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:mmucom
ID: 22873928
Hi blue-genie

if u see my code snippet line 17 "var images:Array = this.firstChild.childNodes;//get the main <pic> nodes in a array" with this i am loading multiple images into predefined movie clip on stage. like this i need to load a text from xml into predefined text field on stage. if u see line from 19 to 61 using this i can able to load text too. but i really wanted to cutdown these lines and make it to simple.

at the same time if u see my attached file i have a invisible button on top of each predefined movie clip. so on each button on release function i set it up in such a way thats need to load a different .XML file on a (gal) frame label. so u have any idea how do we get that??? i hope everything is clear now. if u want more clarification please let me know.

Thanks

0
 
LVL 34

Accepted Solution

by:
Aneesh Chopra earned 500 total points
ID: 22874012
here is the updated FLA and XML file, now it loads  the seperate XMLs,

additionally, I have updated the XML strucutre also, now you can configure seperate XMLs for each button in XML..
gallery-final.fla.txt
images.xml.txt
0
 

Author Comment

by:mmucom
ID: 22874128
Hi aneesh,

Thank you so much for your help its working great. one last thing i am very curious to know about the image grid making in your script. its look like i can add n number of movie clips isn't???. can you please explain me how is it working??. because every time when i add the content in the xml its taking only seven movie clips in a row its something i really wanted to know. can u explain that in a simple words

Thanks again its a great work.
0
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 22874217
yes, you can add n number of movieClip and 7 in a row..

check code on Layer14 > frame 1 > line no  42,43:

var newx = initx+(mc._width+20)*(i%7);
var newy = inity+(mc._height+20)*Math.floor(i/7);


change '7' in both of these lines to change the number in a row..
change "20" in both of these lines to change gap horizontally/vertically inbetween items..

another bit of info:
- change position of single item on stage to set start position (x,y) of the grid..
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now