In retrospect, it seems reasonable that one would need to use a drawXxx()
command to have
beginBitmapFill() affect the graphics port. Anyway, in case this useful to
anyone else, here's a method
that draws a string to a graphics object:
public function drawString(g:Graphics, str:String, x:Number,
y:Number):void
{
var tf:TextField = new TextField();
tf.text = str;
var bmd:BitmapData = new BitmapData(tf.textWidth + 6,
tf.textHeight, true, 0xFFFFFF);
bmd.draw(tf);
var matrix:Matrix = new Matrix();
matrix.createBox(1, 1, 0, x, y);
g.beginBitmapFill(bmd, matrix);
g.drawRect(x, y, bmd.width, bmd.height);
g.endFill();
}
Of course, in actual use, one would probably want to set fonts, colors, etc.
--- In [email protected], "Eric Cooper" <[EMAIL PROTECTED]> wrote:
>
> I have tried this, but it doesn't seem to be working. Here's what I am doing:
>
> override public function renderShape(graphics:Graphics):void
> {
> var matrix:Matrix = new Matrix()
> matrix.createBox(1, 1, 0, this.center.x, this.center.y ); //
> center is the vertex of an angle
> graphics.beginBitmapFill(this.bitmapData, matrix);
> graphics.endFill();
> }
>
> // use bright colors for debugging.
> private function generateBitmapData():void
> {
> this._textField.text = this.angle + "º";
> this._textField.textColor = 0xFF0000;
> this._textField.background = true;
> this._textField.backgroundColor = 0x0000FF;
> _bitmapData = new BitmapData(this._textField.textWidth,
> this._textField.textHeight, false,
0x00FF00);
> _bitmapData.draw(this._textField);
> }
> private function get bitmapData():BitmapData
> {
> if (_bitmapData == null)
> this.generateBitmapData();
> return _bitmapData;
> }
>
> Note that the "real" renderShape() also draws a pie wedge to the canvas - and
> the wedge is visible. As
an aside, though,
> I am also having trouble with drawing the pie wedge - the wedge works fine,
> but if I try to draw just the
arc of the
> wedge, then I find that the arc deforms into a closed shape: the two end
> points are connected by a line.
If I omit
> beginFill() and endFill() calls, relying only on lineStyle(), then connecting
> line goes away, but I start
seeing strange flood
> fills. Reading about Graphics, I see that endFill() plays a role in getting
> draw commands pushed onto
draw stack. I also
> see that the fill specified by beginFill() et al. persists until another
> beginFill() call. Is there some mantra
for turning off
> fill?
>
> Thanks!
> -Eric
>
> --- In [email protected], "Doug McCune" <doug@> wrote:
> >
> > You can draw a TextField to a BitmapData object (using the draw() method)
> > and then use graphics.beginBitmapFill and pass in that BitmapData (make sure
> > to specify the right matrix for where to start the fill). But no, as far as
> > I know there is not way to do it directly, I often use BitmapData as an
> > intermediary to do stuff like that.
> >
> > Doug
> >
> > On Fri, Apr 11, 2008 at 3:50 PM, Eric Cooper <eric@> wrote:
> >
> > > Is there any way to write/draw text directly to a Graphics object? For
> > > that matter is there
> > > anyway to draw text (single line of static text) into a Canvas? I suspect
> > > that the answer is "no",
> > > having searched and searched... but maybe there's some obscure utility
> > > class that I've
> > > overlooked.
> > > Thanks in advance.
> > > -Eric
> > >
> > >
> > >
> >
>