A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: XML data forLoop integration question

  1. #1

    XML data forLoop integration question

    Hi all,

    I have this loop code that counts up the XML nodes and creates menu items for each node, that was taken from a tutorial. How can I have it so after 10 nodes it creates a new column setting them side by side? Moving them say 100px on the x axis? Here is the 1st part of the code that works:

    Code:
    Code:
    var xml:XML = new XML();
    xml.ignoreWhite = true;
    xml.onLoad = function (success:Boolean) {
    	var properties:Array = xml.firstChild.childNodes;
    	for(var i:Number = 0; i<properties.length; i++)
    	{
    		var row:MovieClip = attachMovie("row", "row" + i, getNextHighestDepth(), {xml_data:properties[i]})
    		row._y = i * (row._height + 2);																							
    	}
    }
    xml.load("Properties-Master.xml");
    The code listed above checks the XML file and creates buttons for every node. Here is the second code creating the columns, my friend helped with this but he didn't tell me where to put it with my previous code. Little help anybody?

    Code:
    Code:
    // its better practice to declare all of your variables first and reassigning them instead of redeclaring them over and over.
    var maxRows:Number = 10;
    var numColumns:Number = 0;
    var counter:Number = 1;
    var max:Number = properties.length;
    var columnWidth:Number = 100;
    var rowHeight:Number = 30;
    var xPos:Number;
    var yPos:Number;
    
    for( var i:Number = 0; i < max; i++){
      xPos = columnWidth * numColumns;
      yPos = counter * rowHeight;
      myRow._x = xPos;
      myRow._y = yPos;
      if(counter == maxRows){
        counter = 1;
        numColumns++;
      } else {
        counter++
      }
    Hope this makes sense.

    Thanks!

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    var xml:XML = new XML();
    xml.ignoreWhite = true;
    xml.onLoad = function(success:Boolean) {
    	var maxRows:Number = 10;
    	var numColumns:Number = 0;
    	var counter:Number = 0;
    	var columnWidth:Number = 100;
    	var properties:Array = xml.firstChild.childNodes;
    	var max:Number = properties.length;
    	for (var i:Number = 0; i<max; i++) {
    		var row:MovieClip = attachMovie("row", "row"+i, getNextHighestDepth(), {xml_data:properties[i]});
    		row._x = columnWidth*numColumns;
    		row._y = counter*(row._height+2);
    		if (counter == maxRows) {
    			counter = 0;
    			numColumns++;
    		} else {
    			counter++;
    		}
    	}
    };
    xml.load("Properties-Master.xml");

  3. #3
    I F'ING love you.

    Worked beautifully.

    Thanks!

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center