Jolie Rouge


all ur parentheses Я belong to me


Adobe Flex/AS3 MX:Grid Class

Well, I said it in a previous flex tut, that you shouldn’t manually create your mx:grids cause it’s super ugly, instead of just telling you, I decided I’d show you, heres a basic start class for creating an mx:grid dynamically, you can modify the previous demo code to use it easily, that’s how I tested it.

Table.as
package org.jasonmartin.demo.views.components 
{
	/**
	 * ...
	 * @author Jason Martin
	 */
	import mx.containers.*;
	public class Table {
		private var rows:Array;
		private var pointer:int;
		public static const NAME:String = 'Table';
		public var id:String;
		public function Table() {
			this.pointer = 0;
			this.rows = new Array();			
		}
		public function addRow(row:Array):Boolean {
			this.rows.push(row);
			return true;
		}
		public function addColumn(col:Object):Boolean {
			if (typeof(this.rows[this.pointer]) != 'object'){
				this.rows[this.pointer] = new Array(); //just in case 🙂
			}
			this.rows[this.pointer].push(col);
			return true;
		}
		public function next():int {
			this.pointer++;
			return this.pointer;
		}
		public function previous():int {
			this.pointer--;
			return this.pointer;
		}
		public function resetPointer():Boolean {
			this.pointer = 0;
			return true;
		}
		public function grid():Grid {
			var g:Grid = new Grid();
			g.id = this.id;
			for (this.pointer = 0; this.pointer < this.rows.length;this.pointer++) {
				var r:GridRow = new GridRow();
				r.id = this.pointer.toString();
				for (var i:int = 0; i < this.rows[this.pointer].length; i++ ) {
					var gi:GridItem = new GridItem();
					gi.id = "Row_" + this.pointer + "_Item_" + i;
					gi.addChild(this.rows[this.pointer][i]);
					r.addChild(gi);
				}
				g.addChild(r);
			}
			return g;
		}
	}
}