void ofxXmlSettings::deserialize(ofAbstractParameter & parameter){
	if(!parameter.isSerializable()) return;
	string name = parameter.getEscapedName();
	if(parameter.type()==typeid(ofParameterGroup).name()){
		ofParameterGroup & group = static_cast<ofParameterGroup&>(parameter);
		if(tagExists(name)){
			pushTag(name);
			for(int i=0;i<group.size();i++){
				deserialize(group.get(i));
			}
			popTag();
		}
	}else{
		if(tagExists(name)){
			if(parameter.type()==typeid(ofParameter<int>).name()){
				parameter.cast<int>() = getValue(name,0);
			}else if(parameter.type()==typeid(ofParameter<float>).name()){
				parameter.cast<float>() = getValue(name,0.0f);
			}else if(parameter.type()==typeid(ofParameter<bool>).name()){
				parameter.cast<bool>() = getValue(name,false);
			}else if(parameter.type()==typeid(ofParameter<string>).name()){
				parameter.cast<string>() = getValue(name,"");
			}else{
				parameter.fromString(getValue(name,""));
			}
		}
	}

}
void ofxFlashXFLBuilder :: setupStrokeForShape ( ofxFlashShape* shape )
{
	if( tagExists( "stroke", 0 ) )
	{
		pushTag( "stroke", 0 );
		
		int solidStrokeWeight;
		solidStrokeWeight = getAttribute( "SolidStroke", "weight",  0, 0 );
		
		pushTag( "SolidStroke", 0 );
		pushTag( "fill", 0 );
		
		string fillSolidColor;
		fillSolidColor = getAttribute( "SolidColor", "color", "#000000", 0 );
		fillSolidColor = cleanHexString( fillSolidColor );
		
		float fillAlpha;
		fillAlpha = getAttribute( "SolidColor", "alpha",  1.0, 0 );
		
		shape->setStroke( true );
		shape->setStrokeWeight( solidStrokeWeight );
		shape->setStrokeColor( stringToHex( fillSolidColor ) );
		shape->setStrokeAlpha( fillAlpha );
		
		ofColor c;
		
		popTag();
		popTag();
		popTag();
	}
}
void ofxXmlSettings::serialize(const ofAbstractParameter & parameter){
	if(!parameter.isSerializable()) return;
	string name = parameter.getEscapedName();
	if(name=="") name="UnknownName";
	if(parameter.type()==typeid(ofParameterGroup).name()){
		const ofParameterGroup & group = static_cast<const ofParameterGroup&>(parameter);
		if(!tagExists(name)) addTag(name);
		pushTag(name);
		for(int i=0;i<group.size();i++){
			serialize(group.get(i));
		}
		popTag();
	}else{
		string value = parameter.toString();
		if(!tagExists(name))
			addValue(name,value);
		else
			setValue(name,value);
	}
}
void ofxFlashXFLBuilder :: buildRectangleShape ()
{
	ofxFlashShape* shape;
	shape = new ofxFlashShape();
	
	//-- position & transform.
	
	float cx = domRectangleObject.x + domRectangleObject.objectWidth  * 0.5;		// center point.
	float cy = domRectangleObject.y + domRectangleObject.objectHeight * 0.5;		// center point.
	
	float transformationPointX = cx;												// default transformation point is center.
	float transformationPointY = cy;												// default transformation point is center.
	
	if( tagExists( "transformationPoint", 0 ) )
	{
		pushTag( "transformationPoint", 0 );
		
		transformationPointX = getAttribute( "Point", "x", cx, 0 );
		transformationPointY = getAttribute( "Point", "y", cy, 0 );
		
		popTag();
	}
	
	setupMatrixForDisplayObject( shape );
	
	float shiftX = transformationPointX - cx;
	float shiftY = transformationPointY - cy;
	
	ofxFlashMatrix matrix;
	matrix = shape->matrix();				// get matrix.
	
	float tx = matrix.getTx() + shiftX;
	float ty = matrix.getTy() + shiftY;
	
	matrix.setTx( tx );						// adjust matrix.
	matrix.setTy( ty );
	
	shape->matrix( matrix );				// set matrix.
	
	ofRectangle shapeRect;
	shapeRect.x			= domRectangleObject.x + shiftX;
	shapeRect.y			= domRectangleObject.y + shiftY;
	shapeRect.width		= domRectangleObject.objectWidth;
	shapeRect.height	= domRectangleObject.objectHeight;
	
	shape->setRectangle( shapeRect.x, shapeRect.y, shapeRect.width, shapeRect.height );
	
	setupFillForShape( shape );
	setupStrokeForShape( shape );
	
	addDisplayObjectToFrames( shape );
}
void ofxFlashXFLBuilder :: setupColorForDisplayObject ( ofxFlashDisplayObject* displayObject )
{
	if( tagExists( "color", 0 ) )
	{
		pushTag( "color", 0 );
		
		float alphaMultiplier = getAttribute( "Color", "alphaMultiplier",  1.0, 0 );
		
		displayObject->alpha( alphaMultiplier );
		
		popTag();
	}
}
void ofxFlashXFLBuilder :: setupFillForShape ( ofxFlashShape* shape )
{
	if( tagExists( "fill", 0 ) )
	{
		pushTag( "fill", 0 );
		
		string fillSolidColor;
		fillSolidColor = getAttribute( "SolidColor", "color", "#000000", 0 );
		fillSolidColor = cleanHexString( fillSolidColor );
		
		float fillAlpha;
		fillAlpha = getAttribute( "SolidColor", "alpha",  1.0, 0 );
		
		shape->setFill( true );
		shape->setFillColor( stringToHex( fillSolidColor ) );
		shape->setFillAlpha( fillAlpha );
		
		popTag();
	}
}
void ofxFlashXFLBuilder :: setupMatrixForDisplayObject ( ofxFlashDisplayObject* displayObject )
{
	if( tagExists( "matrix", 0 ) )
	{
		pushTag( "matrix", 0 );
		
		float a		= getAttribute( "Matrix", "a",  1.0, 0 );
		float b		= getAttribute( "Matrix", "b",  0.0, 0 );
		float c		= getAttribute( "Matrix", "c",  0.0, 0 );
		float d		= getAttribute( "Matrix", "d",  1.0, 0 );
		float tx	= getAttribute( "Matrix", "tx", 0.0, 0 );
		float ty	= getAttribute( "Matrix", "ty", 0.0, 0 );
		
		ofxFlashMatrix matrix;
		matrix.set( a, b, c, d, tx, ty );
		
		displayObject->matrix( matrix );
		
		popTag();
	}
}
//---------------------------------------------------------
void ofXMLSettings::clearTagContents(string tag, int which){
	//we check it first to see if it exists
	//otherwise setValue will make a new empty tag
	if( tagExists(tag, which) )setValue(tag, "", which);
}