Create a colour picker bitmap

This code will generate a colour picker bitmap that can be used to select a colour in a drawing application.

private function getColorPicker(w:Number, h:Number):Bitmap
{
	var container:Sprite = new Sprite();
	var colourSprite:Sprite = new Sprite();
	var colours:Array = [0xff0000,0xffff00, 0x00ff00, 0x00ffff,0x0000ff,0xff00ff, 0xff0000];
	var alphas:Array = [1, 1, 1, 1, 1, 1, 1];
	var ratios:Array = [0, 42, 85, 128, 170, 212, 255];
	var mat:Matrix = new Matrix();
	mat.createGradientBox(w, h);
	colourSprite.graphics.beginGradientFill(GradientType.LINEAR, colours, alphas, ratios,mat);
	colourSprite.graphics.drawRect(0,0,w, h);
	container.addChild(colourSprite);			
	var shade:Sprite = new Sprite();
	colours = [0xffffff, 0x000000];
	alphas = [1 , 1];
	ratios = [0, 0xff];
	mat = new Matrix();
	mat.createGradientBox(w, h, Math.PI / 2);
	shade.graphics.beginGradientFill(GradientType.LINEAR, colours, alphas, ratios,mat);
	shade.graphics.drawRect(0, 0, w, h);
	var r:BlendMode
	shade.blendMode = BlendMode.HARDLIGHT;
	container.addChild(shade);
	var bmd:BitmapData = new BitmapData(w, h);
	bmd.draw(container);
	var bmp:Bitmap = new Bitmap(bmd);
	addChild(bmp);
	return bmp;
}

Retrieve all copy from an XML document

Method looks at all descendents if the node kind is text it will add it to the return string.

private function getTextContentFromXML(xml:XML):String 
{
	var str:String = "";
	var xmlList:XMLList = xml.descendants("*");
	for (var i:uint = 0; i < xmlList.length(); i++) {
		if (xmlList[i].nodeKind() == "text") {
			str = str.concat(bigXMLList[i]);
		}
	}
	return str;
}

Will glyph render?

This method will take a Font and a String and returns a String of glyphs that fail to render. The method uses a binary search algorythm where the string is devided into equal length sub-strings. These are then tested with the Font.hasGlyphs() method, if this fails the sub-string is fed into the method until the string passes or its length is 1. If this character fails it is added to the failedGlyphs string.

private function getFailedGlyphs(font:Font, str:String):String {
	var len:uint = str.length;
	var failedGlyphs:String = "";
	if (len > 1) {
		var split:uint = Math.floor(len / 2);
		if (!font.hasGlyphs(str.substr(0, split))) {
			failedGlyphs += getFailedGlyphs(font,str.substr(0,split))
		}
		if (!font.hasGlyphs(str.substr(split))) {
			failedGlyphs += getFailedGlyphs(font,str.substr(split))
		}
	}else {
		if (!font.hasGlyphs(str)) {
			failedGlyphs += str;
		}
	}
	return failedGlyphs;
}