This content has been marked as final. Show 3 replies
For what you are doing, I would make bitmaps of the numerals - either as GIF or PNG or Flash so you can have transparent backgrounds. Embed the symbols and use either an Array or an Object to index them. So the graphic for "0" is in the 0 position, etc.
private var zeroImage:Class;
... // the others here
var digits:Array = [zeroImage, oneImage, twoImage, ... ];
If you use PNG or GIF, just use the source part of the Embed and leave off the symbol.
You can create a BitmapData object, create a Label object, set the Label to the digit you want, and pass the Label object to the draw() method of the BitmapData object.
It won't do transparency, so you'll need to set the bitmap background to whatever you need (I think?) before you draw. You can then draw the bitmapdata using the beginBitmapFill method of the Graphics object - however I can't see how one can move the origin, so you may need to make a sprite for each one, which may leave you with the same performance problem.
So, not a solution, but I spent a bit of time playing around with it and you may be able to get it to work. I had a problem getting the Label to calculate its sizes, etc. - this is because I don't want to parent it. Shouldn't I be able to just call mylabel.initialize() to force it to figure out its size - I can't call measure() directly.
Since I seem to come across this question in various places, here is what is a sort-of workable solution.
By all means, if somebody has a nicer way of doing this, hit reply now and tell me how.
- create a (invisible) component on startup that has labels for all the different text you need (and different fonts
for that matter) and capture the BitmapData for the labels and store them
- in the renderer, use graphics.beginBitmapFill(bitmapData, new Matrix( 1,0,0,1,xAdjust), false);
- xAdjust is the X coordinate were the custom text is supposed to go (same deal for Y)
This seems a very long way to do what I need to do, but it works and is sooo much quicker than creating hundreds of labels (the addChild method seems very slow). In my particular app there are about 10 different letters and about 30
rows with 60 letters each and this is quick enough (whereas 30*60 addChilds aren't ;-)
I do believe a (fast) graphics.drawText method would be a nice feature for Flex 3.0 ;-)