i would like to know if it is possible to have a letter that is made up of multiple colors. for example above you will see a hebrew letter. the DOT underneath it is actually part of the letter, but it is a different color.
is it possible to have this same functiona开发者_JS百科lity in flash? what i would need to do is upload an XML file with all the words, and i would need all the dots below the letters to be a different color.
the letter came from this site:
http://www.oryanit.com/site/2.1.asp?user=oryanit&site=56
You can't do it in Flash with dynamic TextFields I am afraid.
here is a basic example:
import flash.text.TextField;
import flash.text.TextFormat;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.Rectangle;
import flash.geom.Point;
/*
* This is your character
*/
var tf:TextField = new TextField();
tf.selectable = false;
tf.text = "B";
addChild(tf);
var fmt:TextFormat = new TextFormat();
fmt.size = 50;
tf.setTextFormat(fmt);
//Creating a bitmapData from the TextField
var tfBD:BitmapData = new BitmapData(tf.textWidth, tf.textHeight);
tfBD.draw(tf);
var tfB:Bitmap = new Bitmap(tfBD);
addChild(tfB);
//Creating the top part of the character
var tfTopBD:BitmapData = new BitmapData(tfBD.width, tfBD.height/2);
tfTopBD.copyPixels(tfBD, new Rectangle(0, 0, tfBD.width, tfBD.height/2), new Point(0, 0));
var tfTopB:Bitmap = new Bitmap(tfTopBD);
addChild(tfTopB);
//Creating the bottom part of the character
var tfBottomBD:BitmapData = new BitmapData(tfBD.width, tfBD.height/2);
tfBottomBD.copyPixels(tfBD, new Rectangle(0, tfBD.height/2, tfBD.width, tfBD.height/2), new Point(0, 0));
var tfBottomB:Bitmap = new Bitmap(tfBottomBD);
addChild(tfBottomB);
tfB.x = Math.round(stage.stageWidth/2 - tfB.width/2);
tfB.y = Math.round(stage.stageHeight/2 - tfB.height/2);
tf.x = tfB.x - 50;
tf.y = tfB.y;
tfTopB.x = tfB.x + 50;
tfTopB.y = tfB.y;
tfBottomB.x = tfB.x + 50;
tfBottomB.y = tfB.y + tfTopB.height + 10;
Basically I create two bitmapData objects and I copy the contents of textField into them, so I get the top part and the bottom part of the character. Then you can recolor them as you wish.
For coloring in AS3 I would recommend to use the Greensock tweening engine, whish I prefer to using colorMatrixes and other ugly stuff. http://www.greensock.com/
Hope it suits you, Rob
精彩评论