SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Retrieve xml data in flash horizontally

    Hello friends,

    I'm trying to figure out how to display multiple data (retrieved from xml files using a for loop) horizontally in flash. For example, I'd like to display images (fetched from the database using XML) in a flash file where in i want to display 3 records in a row and rest of the images to appear in the next row having the set of 3 images in each rows.

    I'm having a hard time handling this task. any idea on how this can be possible? Please find below the code that I am using at the moment to display 1 image but can't find a solution display multiple in different rows.

    Code:
    // Create new XML Object and set ignoreWhite true
    book_xml = new XML();
    book_xml.ignoreWhite = true;
    // Setup load handler which just invokes another function
    // which will do the parsing of our XML
    book_xml.onLoad = function(sucess) {
    	if (sucess) {
    			processBook(book_xml);
    	}
    };
    // Load up the XML file into Flash
    book_xml.load('book.xml');
    // This is the function that will be called when
    // our XML document is loaded succesfully
    function processBook(xmlDoc_xml) {
            // xmlDoc_xml is now a reference to the XML
            // object where our information is stored
            for (a in xmlDoc_xml.firstChild.childNodes) {
                    trace(a + ' ' + xmlDoc_xml.firstChild.childNodes[a]);
            }
    }
    
    function processBook(xmlDoc_xml) {
            // xmlDoc_xml is now a reference to the XML
            // object where our information is stored
            book = new Object();
            book.authors = new Array();
            for (var n = 0; n<xmlDoc_xml.firstChild.childNodes.length; n++) {
                    if (xmlDoc_xml.firstChild.childNodes[n].nodeName == "Authors") {
                            //trace(xmlDoc_xml.firstChild.childNodes[n].firstChild.firstChild.nodeValue);
                            book.authors.push(xmlDoc_xml.firstChild.childNodes[n].firstChild.firstChild.nodeValue);
    						price_txt.text=xmlDoc_xml.firstChild.childNodes[n].firstChild.firstChild.nodeValue;
    						//frame_holder_mc.getURL(xmlDoc_xml.firstChild.childNodes[n].firstChild.firstChild.nodeValue;
                 } else if (xmlDoc_xml.firstChild.childNodes[n].nodeName == "ImageUrlSmall") {
                            //trace(xmlDoc_xml.firstChild.childNodes[n].firstChild.nodeValue);
                            book.authors.push(xmlDoc_xml.firstChild.childNodes[n].firstChild.nodeValue);
    						//price_txt.text=xmlDoc_xml.firstChild.childNodes[n].firstChild.firstChild.nodeValue;
    						frame_holder_mc.loadMovie(xmlDoc_xml.firstChild.childNodes[n].firstChild.nodeValue);
                 }else{
                            //trace(xmlDoc_xml.firstChild.childNodes[n].firstChild.nodeValue);
                            book[xmlDoc_xml.firstChild.childNodes[n].nodeName] = xmlDoc_xml.firstChild.childNodes[n].firstChild.nodeValue;
    			
                    }
            }
    }


    Any help appreciated. Thanks in advance.

  2. #2
    SitePoint Wizard jim_morrison3's Avatar
    Join Date
    Apr 2004
    Location
    UK
    Posts
    2,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can do this by using nested for (say having i and j) loops, both going from 0 to 2. In the inner for loop you can set up the x position of the images while in the outer for loop you can set up their y position.
    Good Luck!
    There are things known and Things unknown
    And in between are the Doors.
    I love hand Coding.

  3. #3
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried your solution, but its not working. Can you give me some example based on my code or a small code that you may already have.

    Following is the code that I am using but having no success;

    Code:
    // Create new XML Object and set ignoreWhite true
    book_xml = new XML();
    book_xml.ignoreWhite = true;
    // Setup load handler which just invokes another function
    // which will do the parsing of our XML
    book_xml.onLoad = function(sucess) {
    	if (sucess) {
    		processBook(book_xml);
    	}
    };
    // Load up the XML file into Flash
    book_xml.load('book.xml');
    // This is the function that will be called when
    // our XML document is loaded succesfully
    function processBook(xmlDoc_xml) {
            // xmlDoc_xml is now a reference to the XML
            // object where our information is stored
            for (a in xmlDoc_xml.firstChild.childNodes) {
                    trace(a + ' ' + xmlDoc_xml.firstChild.childNodes[a]);
            }
    }
    
    function processBook(xmlDoc_xml) {
            // xmlDoc_xml is now a reference to the XML
            // object where our information is stored
            book = new Object();
            book.authors = new Array();
    		var depth = 0;
    		var nextY = 30;
    		var nextX = 100;
            //for (var n = 0; n<xmlDoc_xml.firstChild.childNodes.length; n++) {
    			//authorsNode=xmlDoc_xml.firstChild.childNodes[n];
    			//for(var d=0; d<authorsNode.firstChild.childNodes.length; d++){
    				
    				for(var y=0; y<=2; y++){
    					for( var x=0; x<=2; x++){
    						_root.tempMC = attachMovie ("box", "box" + count, depth ++, {_y : (nextY) , _x : (nextX)} );
    						_root.tempMC.name_txt.text = trace(xmlDoc_xml.firstChild.childNodes[y].firstChild.childNodes);
    						_root.tempMC.img_holder.loadMovie(trace(authorsNode.firstChild.nextSibling.firstChild.nodeValue));
    						nextX += tempMC._width + 2;
    						count ++;
    					}
    					nextY += tempMC._height + 2;					
    				}
    				//price_txt.text=authorsNode.firstChild.childNodes;
    				//frame_holder_mc.loadMovie(authorsNode.firstChild.nextSibling.firstChild.nodeValue);
    			//}
    			
    			/*if (xmlDoc_xml.firstChild.childNodes[n].nodeName == "Authors") {
                            //trace(xmlDoc_xml.firstChild.childNodes[n].firstChild.firstChild.nodeValue);
                            book.authors.push(xmlDoc_xml.firstChild.childNodes[n].firstChild.firstChild);
    						price_txt.text=xmlDoc_xml.firstChild.childNodes[n].firstChild.firstChild;
    						frame_holder_mc.loadMovie(xmlDoc_xml.firstChild.firstChild.firstChild.nextSibling.firstChild.nodeValue);
                 }/* else if (xmlDoc_xml.firstChild.childNodes[n].nodeName == "ImageUrlSmall") {
                            //trace(xmlDoc_xml.firstChild.childNodes[n].firstChild.nodeValue);
                            book.authors.push(xmlDoc_xml.firstChild.childNodes[n].firstChild.nodeValue);
    						//price_txt.text=xmlDoc_xml.firstChild.childNodes[n].firstChild.firstChild.nodeValue;
    						frame_holder_mc.loadMovie(xmlDoc_xml.firstChild.childNodes[n].firstChild.nodeValue);
                 } *//*else {
                            //trace(xmlDoc_xml.firstChild.childNodes[n].firstChild.nodeValue);
                            book[xmlDoc_xml.firstChild.childNodes[n].nodeName] = xmlDoc_xml.firstChild.childNodes[n].firstChild.nodeValue;
    			
                    }*/
            //}
    }
    It would be really nice if you can help me get this sorted or get me an example of how it should happen.

    Thanks
    Varsha

  4. #4
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi friends,

    I'm trying to figure out how to display the thumbnails of images in flash in the form of rows and columns (3X3 grid) using XML and a Next button to move on next page of the thumbnails. For example, I'd like to display images (fetched from the database using XML) in a flash file where in i want to display 3 records in a row and rest of the images to appear in the next row having the set of 3 images in each rows.

    I'm having a hard time handling this task. any idea on how this can be possible? Please find below the code that I am using at the moment to display all the images in single row, but can't find a solution display multiple in different rows.

    [Action Script Code]

    myPhoto = new XML();
    myPhoto.ignoreWhite = true;
    myPhoto.onLoad = function(success) {
    //portfolioTag = this.firstChild;
    numimages = this.firstChild.childNodes.length;
    spacing = 152;
    rowwidth=-250;
    rowheight=79;
    //for (k=0; k<numimages; k++) {
    for (j=0; j<3; j++){
    for (i=0; i<numimages; i++) {
    this.picHolder = this.firstChild.childNodes[i];
    this.thumbHolder = thumbnails.createEmptyMovieClip("thumbnail"+i, i);
    if (theside == 1)
    {
    thumbclip._x = 0;
    theside = 2;
    }
    else
    {
    thumbclip._x = 100;
    theside = 1;
    }
    thumbclip._y = Math.floor(n / 2) * 77;
    this.thumbHolder._x = i*spacing;
    //this.thumbHolder._y = i+rowheight;
    this.thumbLoader = this.thumbHolder.createEmptyMovieClip("thumbnail_image", this.getNextHighestDepth());
    this.thumbLoader.loadMovie(this.picHolder.attributes.thmb);
    this.thumbHolder.title = this.picHolder.attributes.title;
    this.thumbHolder.main = this.picHolder.attributes.main;
    this.thumbHolder.onRelease = function() {
    loader.loadMovie(this.main);
    title_txt.text = this.title;
    };
    }
    //this.thumbHolder._x = j*spacing;
    //this.thumbHolder._x = "<br />";
    //this.thumbHolder._y= i+rowheight;
    }
    //this.thumbLoader._y = j*rowheight;
    //this.thumbLoader._x = rowwidth;
    //}
    };
    myPhoto.load("xmlphoto.xml");


    [/Action Script Code]

    Any help appreciated. Thanks in advance.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •