Flash/AS3 Classes

gpShapes - Gradients

The following example displays the gpShapes Class with the gradient options. To create a gradient, add multiple hexadecimal colors (comma-delimited) to the bgColor option. You can also set the fill_type to radial (the default is linear). If the fill_type is linear, you can also rotate the gradient using the gradient_rotation option (in degrees). The default gradient_rotation is Math.PI/2 which will create a horizontal gradient.

In the example below, the configuration file is loaded with the gpUrlLoader Class. The gpConfig class is used to retrieve the specific XMLList and convert it to an object.

    import flash.events.*;
    import com.grasshopper.utils.*;
	
	var config:gpConfig;
	
	var ldr:gpUrlLoader = new gpUrlLoader();
	ldr.addEventListener(Event.COMPLETE, xmlLoaded);
	ldr.addEventListener(gpUrlLoader.LOADERROR, ioError);
	ldr.init('config.xml', 'xml');

	function xmlLoaded(event:Event):void {
		var xl:XML = ldr.getXML();
		config = new gpConfig(xl);
		var configItem:Object = config.getChildByAttributeObject('pLayout', 'pStyles', 'cType', 'shape1');
		var myShape:gpShapes = new gpShapes();
		myShape.createShape(configItem);
		addChild(myShape);
		myShape.x = 100;
		myShape.y = 100; 
	}	
	
	function ioError(e:Event):void {
		trace('Error loading file');
	}	

For documentation about the gpShapes AS3 Class, view the blog post.