Search code examples
actionscriptspritevector-graphicsactionscript-3

render text to Sprite.graphics -- as3 -?


Because I'm a terrible, bad person who likes to do things differently for no reason, I'd love to be able to do something like mySprite.graphics.drawText(...).

As I understand things, the only way to get text currently is to create a TextField and add it as a child of mySprite. In my particular situation I'd rather not do that.

Any advice appreciated!

ooo


Solution

  • The TextField class inherits the InteractiveObject class which inherits the DisplayObject class. Display objects cannot be displayed unless they are programmed to, which is what addChild does.

    See http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/TextField.html for more information.

    Also, from http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/states/AddChild.html -

    The AddChild class adds a child display object, such as a component, to a container as part of a view state. You use this class in the overrides property of the State class.