0 Replies - 4370 Views - Last Post: 12 December 2009 - 06:57 PM

#1 SirenDesigns   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 03-December 08

AS3 Help with for loop dynamic text from XML!

Post icon  Posted 12 December 2009 - 06:57 PM

I'm trying to get some dynamic text to show up in my image gallery. I tried creating a for loop through my XML to dynamically display the title and description of my image gallery, but it's displaying either the first title over and over or the second, or all of them at the same time. This is for a final project and my time is very limited. Please help!!! Thanks !

package {

	import flash.display.MovieClip;//importing movieclip
	import flash.net.*;//importing data classes
	import flash.display.*;
	import flash.events.*;
	import flash.text.*;

	public class Gallery extends MovieClip {

		var my_images:XMLList;//creating a variable that is a list of items in my XML
		var totalThumbs:Number;

		var container_mc:MovieClip;

		var x_counter:Number=0;
		var y_counter:Number=0;

		public function Gallery():void {
			var myXMLLoader:URLLoader = new URLLoader();//creating an instance of the URLLoader class
			myXMLLoader.load(new URLRequest("gallery.xml"));//linking to the gallery.xml
			myXMLLoader.addEventListener(Event.COMPLETE, processXML);//adding an event listener to the URL loader class to 'processXML' where

		function processXML(e:Event):void {//creating a function processXML
			var myXML:XML=new XML(e.target.data);// actually processing the XML from the main.xml file by creating a variable called myXML and telling it to load data

			//[email protected];
			//xPos=0;//xposition for all of the thumbnails
			//yPos=0;//yposition for all of the thumbnails
			//[email protected];
			//[email protected];
			//[email protected];
			//[email protected];
			totalThumbs=my_images.length();//setting totalThumbs (which is a number) to the length of images in the XML file


		function createContainer():void {
			container_mc = new MovieClip();
			container_mc.x=0;//positioning the container

			container_mc.addEventListener(MouseEvent.CLICK, callFull);

		function callThumbs():void {
			for (var i:Number = 0; i < totalThumbs; i++) {//creating a for loop to loop through all of the thumbnails

				var thumb_url=my_images[i][email protected];

				var loadThumb = new Loader();
				loadThumb.load(new URLRequest(thumb_url));
				loadThumb.contentLoaderInfo.addEventListener(Event.COMPLETE, thumbLoaded);


				//loadThumb.x = (my_thumb_width+100)*x_counter;
				//loadThumb.y = (my_thumb_height+100)*y_counter;

				loadThumb.y=30*y_counter;//positioning the space between the thumbs

				if (x_counter+1<1) {//replaced 1 pixels with columns... makes 1 column
				} else {

		function thumbLoaded(e:Event):void {
			var my_thumb:Loader=Loader(e.target.loader);

		function callFull(e:MouseEvent):void {
			var full_loader:Loader = new Loader();
			var full_url=my_images[e.target.name][email protected];
			full_loader.load(new URLRequest(full_url));
			full_loader.contentLoaderInfo.addEventListener(Event.INIT, fullLoaded);

			//container_mc.removeEventListener(MouseEvent.CLICK, callFull);

		function fullLoaded(e:Event):void {
			var my_loader:Loader=Loader(e.target.loader);

			//my_loader.x = (stage.stageWidth - my_loader.width)/2;
			//my_loader.y = (stage.stageHeight - my_loader.height)/2;
			my_loader.addEventListener(MouseEvent.CLICK, removeFull);
			var i:Number = 0;
		for each (var link:XML in my_images) {	//creating a for loop through the links in the XML file 
					//title_tf.text=my_images[i][email protected];	//Insert the title text [email protected] reads the link's "TITLE" attribute)
					trace(my_images[0][email protected]);
					//info_tf.text=my_images[i][email protected]
					//title_tf.autoSize=TextFieldAutoSize.LEFT;//Autosizing the text so that the text is left-justified inside of the textfield
					i++;//Increment the menu button counter, so we know how many buttons there are

		function removeFull(e:MouseEvent):void {
			var my_loader:Loader=Loader(e.currentTarget);

			container_mc.addEventListener(MouseEvent.CLICK, callFull);

	}//closing the Main constructor function

}//closing the package 

This post has been edited by SirenDesigns: 12 December 2009 - 06:58 PM

Is This A Good Question/Topic? 0
  • +

Page 1 of 1