/**
 * @class       com.nid.draw.Quad
 * @author      NidiNiam (a.k.a. Fernando Sánchez)
 * @version     0.1
 * @description Implements the drawing behaviours of the FreeLine Class.
 *              <p>
 *		        Provides methods for drawing a FreeLine with or without border
 * 				in separate moviclips from a parent movieclip given.
 * @usage       <pre>FreeLine.FreeLineMethod(FreeLineParam/s);</pre>
 * @param       none  -- no class input parameters.
 * -----------------------------------------------
 * Latest update: June 20, 2008
 * -----------------------------------------------
 * AS2 version 2008, NidiNiam [nidiniam@gmail.com]
 * -----------------------------------------------
 *   Functions:
 *       Quad()
 * 			//public
 *           1.  drawMe(mc,FL)
 * 			//private
 *           2.  drawBorderFreeLine(mc,FL)
 *  ----------------------------------------------
 *  Updates may be available at: http://
 *  ----------------------------------------------
**/

import flash.geom.Matrix;
import com.nid.drawData.FreeLineData;

class com.nid.draw.FreeLine
{
	/**
	 * @property none  -- no class properties.
	**/

    function FreeLine(){
        //customTrace ("com.nid.draw.FreeLine Class loaded");
    }

// 1. drawMe ----------------------------------------

    /**
     * @method  drawMe
     * @description  Draws a FreeLine.
     * @usage  <pre>FreeLine.drawMe(mc,FreeLineData);</pre>
     * @param   mc  (MovieClip)  -- the movieclip where the FreeLine is going to be written.
	 * @param   FL   (FreeLineData)   -- a valid FreeLineData Object with all the values necessary for its drawing.
     * @return  (Void)
    **/
    public function drawMe(mc:MovieClip, FL:FreeLineData):Void {
		//check if target movieclips exist in given mc
		//and create or reset if necessary
		(mc._borderMC == undefined)?mc.createEmptyMovieClip("_borderMC", 2):mc._borderMC.clear();
		(mc._fillMC == undefined)?mc.createEmptyMovieClip("_fillMC", 1):mc._fillMC.clear();
        //customTrace("FreeLine data object -->" + FL.name);
		//draw outline
		if (FL.borderThick > 0) {
			drawBorderFreeLine(mc,FL);
		}
    }

// 2. drawBorder ----------------------------------

    /**
     * @method  drawBorderFreeLine
     * @description  Draws the border of a FreeLine.
     * @param   mc  (MovieClip)  -- the movieclip where the FreeLine is going to be written.
	 * @param   FL  (FreeLineData)  -- a valid FreeLineData Object with all the values necessary for its drawing.
    **/
    //BorderRects
	private function drawBorderFreeLine(mc:MovieClip,FL:FreeLineData):Void {
		mc._borderMC.lineStyle(FL.borderThick, FL.borderColor);
		var tempPoint:Array = new Array();
		tempPoint = String(FL.pointArray[0]).split("#");
		//customTrace("initPoint: "+tempPoint);
		mc._borderMC.moveTo(tempPoint[0], tempPoint[1]);
		for (var i:Number = 1; i < FL.pointArray.length; i++) {
			tempPoint =  new Array();
			tempPoint = String(FL.pointArray[i]).split("#");
			if (tempPoint.length > 2) {//draw curve
				//customTrace("curvePoint: "+tempPoint);
				mc._borderMC.curveTo(Number(tempPoint[0]), Number(tempPoint[1]), Number(tempPoint[2]), Number(tempPoint[3]));
			}else {//draw line
				//customTrace("linePoint: "+tempPoint);
				mc._borderMC.lineTo(Number(tempPoint[0]), Number(tempPoint[1]));
			}
		}
	}
	
	//customized trace
	private function customTrace(msg:String){
		trace("[][] FreeLine: " + msg);
	}
}