Posted in Adobe, Flash
07/26 2006

AS2 :: XMLMenu Class

Goal: minimize the amount of code rewrite involved in creating XML-based menus in Flash. You can customize the Class to match the structure of your XML file.

class org.thesourcecode.utils.XMLMenu extends MovieClip
{
	//declare your variables
	private var _i:Number;
	private var _j:Number;
	private var _mainTL;
	private var _btns:XML;
	private var _butz:Array;
	private var _tmpX:Number;
	private var _tmpY:Number;
	private var _btn;
	private var _xmlfile:String;
	private var _menutarget:MovieClip;
	private var _space:Number;
	private var _vertical:Boolean;
 
	public function XMLMenu()
	{
 
	}//end constructor
 
	public function buildMenu( file:String,target:MovieClip, space:Number, vertical:Boolean )
	{
		_buildIt( file, target, space, vertical );
	}//end public function
 
	private function _buildIt( filesource, destination, separation, isVertical )
	{
		_xmlfile = filesource;
		_btns = new XML();
		_btns.ignoreWhite = true;
		_btns.onLoad = function()
		{
			_menutarget = destination;
			_space = separation;
			_vertical = isVertical;
			_mainTL = _menutarget._parent;
			_butz = this.firstChild.childNodes;
			for (_i=0,_j=1; _i<_butz .length; _i++,_j++)
			{
				_space = _i*separation;
				if (_vertical)
				{
					_tmpX = 0;
					_tmpY = _space;
				} 
				else
				{
					_tmpX = _space;
					_tmpY = 0;
				}
				_btn = _menutarget.attachMovie( "btn","btn"+_j,_i+100,{_x:_tmpX,_y:_tmpY} );
				_btn.selector._visible = false;
				_btn.sec.lbl.text = _butz[_i].attributes.lbl;
				_btn.loc = _butz[_i].attributes.loc;
				_btn.hdr = _butz[_i].attributes.hdr;
				_btn.desc = _butz[_i].attributes.desc;
				_btn.onRollOver = _mainTL.rollover;
				_btn.onRollOut = _mainTL.rollout;
				_btn.onPress = _mainTL.select;
				_mainTL.btns.push( "btn"+_j );
			}
		}
		_btns.load( _xmlfile );
	}//end main menu function
}//end class

Download the easy-install extension here.
Documentation can be found here.

This Post tags: ,

 

USER COMMENTS

Track comments via RSS 2.0 feed. Feel free to post the comment, or trackback from your web site.

Currently there are no comments related to article "AS2 :: XMLMenu Class".

Get Adobe Flash playerPlugin by wpburn.com wordpress themes