Looks right to me.  Those are the rules today.  Why is having a child
TextField so bad?  The Bitmaps can be expensive.

 

________________________________

From: [email protected]
[mailto:[EMAIL PROTECTED] On Behalf Of Derek Adams
Sent: Saturday, April 19, 2008 10:07 AM
To: [email protected]
Subject: [flexcomponents] Drawing text on a component without adding
subcomponents

 

I have a custom component that needs to be able to paint a label on 
its graphics context without adding a subcomponent for it. I figured 
out a way to do it, but it seems like a hack. Does anybody know a 
better way? Here is the code.

// Create an auto-sized text field.
var label:IUITextField = new UITextField();
label.autoSize = TextFieldAutoSize.LEFT;
label.text = "String I want to render";

// Draw the text into a bitmap.
var bm:BitmapData = new BitmapData(label.width, label.height);
bm.draw(label);

// Draw bitmap on the graphics of the component.
comp.graphics.beginBitmapFill(bm, null, false);
comp.graphics.drawRect(0, 0, bm.width, bm.height);
comp.graphics.endFill();

Any ideas?

Thanks,
Derek

 

Reply via email to