Skip to main content
July 20, 2011
Question

i want to write text in graphics sprite

  • July 20, 2011
  • 1 reply
  • 1208 views

i want to write text in this sprite

i use thes method but not work when i add textfield to sprite the rect become very small

function drawRect():Sprite
        {
            var redRect:Sprite = new Sprite();
            redRect.graphics.beginFill(0xff0000);    // red
            redRect.graphics.drawRect(0,0,30, 30);
            redRect.graphics.endFill();
           
            var number:TextField =new TextField();
            number.text = "1";
           
            number.x= 15;
            number.y= 15;
            redRect.addChild(number);
           
            return redRect;
        }

This topic has been closed for replies.

1 reply

Adobe Employee
July 21, 2011

flash.text.TextField is not a class in TLF but in player runtime. Pls post it to http://forums.adobe.com/community/webplayers/flash_player

July 21, 2011

i use this code to insert graphic in text flow

but when i add text to it  not show and the graphic be very small

(mytextflow.interactionManager as EditManager).insertInlineGraphic( drawRect(), 15, size, "none",changedSelection );

function drawRect():Sprite
        {
            var redRect:MovieClip  = new MovieClip ();
            redRect.graphics.beginFill(0xff0000);    // red
            redRect.graphics.drawRect(0,0,30, 30);
            redRect.graphics.endFill();
           
            var number:TLFTextField =new TLFTextField();
            number.text = "1";
           
            redRect.addChild(number);

           
            return redRect;
        }

July 22, 2011

Hi:

What you wanted is to make a Red Sprite contains a TextField in the inline graphic element, right?

I think you needed to handle the source Sprite's width and height by yourself. The width and height parameter in the EditManager's insertInlineGraphic function is to set the width and height of the Inline Graphic Element which is the container of your source sprite. The following codes work  fine on my envirnoment. Hope they are helpful:

package

{

import flash.display.Sprite;

import flash.text.TextField;

import flashx.textLayout.container.ContainerController;

import flashx.textLayout.edit.EditManager;

import flashx.textLayout.conversion.TextConverter;

import flashx.textLayout.edit.EditManager;

import flashx.textLayout.elements.TextFlow;

import flashx.undo.UndoManager;

public class TestInlineGraphic extends Sprite

{

private var redRect:Sprite=null;

public function TestInlineGraphic()

{

var textFlow:TextFlow = TextConverter.importToFlow( "How now brown cow.", TextConverter.PLAIN_TEXT_FORMAT );

textFlow.flowComposer.addController( new ContainerController( this ));

var editManager:EditManager = new EditManager( new UndoManager() );

textFlow.interactionManager = editManager;

textFlow.flowComposer.updateAllControllers();

editManager.selectRange( 3,  3);

editManager.insertInlineGraphic( drawRect(), 20, 20, "none" );

}

function drawRect():Sprite

{

redRect  = new Sprite ();

redRect.graphics.beginFill(0xff0000);    // red

redRect.graphics.drawRect(0,0,30, 30);

redRect.graphics.endFill();

var number:TextField =new TextField();

number.text = "1";

number.width=20;

number.height=20;

redRect.addChild(number);

return redRect;

}

}

}


thanks Gang Cai for your help

the problem it's about size but not size of spriteit's about font size

i change font size and it work great