Text 3D objects are represented by the TextField3D
class, from the away3d.primitives
package. Creating a text 3D object requires two steps:
TextField3D
object.Let's create an application called FontDemo
that creates a 3D textfield and adds it to the scene.
package {
We import the TextField3D
class, making it available within our application.
import away3d.primitives.TextField3D;
The VectorText
class will be used to extract the fonts from the embedded SWF file.
import wumedia.vector.VectorText; public class FontDemo extends Away3DTemplate {
The Fonts.SWF
file was created by compiling the Fonts
class above. We want to embed this SWF file as raw data, so we specify the MIME type to be application/octet-stream
.
[Embed(source="Fonts.swf", mimeType="application/octet-stream")] protected var Fonts:Class; public function FontDemo() { super(); } protected override function initEngine():void { super.initEngine();
Before any TextField3D
objects can be created we need to extract the fonts from the embedded SWF file. This is done by calling the static extractFonts()
function in the VectorText
class, and passing a new instance of the embedded SWF file. Because we specified the MIME type of the embedded file to be application/octet-stream
, a new instance of the class is created as a ByteArray
.
VectorText.extractFont(new Fonts()); } protected override function initScene():void { super.initScene(); this.camera.z = 0;
Here we create the new instance of the TextField3D
class. The first parameter is the font name, which corresponds to the font name included in the embedded SWF file. The TextField3D
constructor also takes an init
object, whose parameters are listed in the next table.
var text:TextField3D = new TextField3D("Vera Sans", { text: "Away3D Essentials", align: VectorText.CENTER, z: 300 } ); scene.addChild(text); } } }
The following table shows you the init
object parameters accepted by the TextField3D
constructor.
Parameter |
Type |
Default Value |
Description |
---|---|---|---|
|
20 |
The font size in pixels. | |
|
20 |
Determines the amount of space between lines in a paragraph. | |
|
0 |
Determines the amount of space between each character. | |
|
"" |
The text to display. | |
|
500 |
The width of the drawing area. If the text is greater than this number then we start wrapping to the next line. To disable wrapping set the | |
|
"TL" or VectorText.TOP_LEFT |
Defines the alignment of the text. The |
When the application is run, the scene will contain a single 3D object that has been created to spell out the words "Away3D Essentials" and formatted using the supplied font. At this point, the text 3D object can be transformed and interacted with, just like other 3D object.