A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: embedded fonts using AS3 string

  1. #1
    Senior Member
    Join Date
    Apr 2003
    Location
    Seattle
    Posts
    177

    embedded fonts using AS3 string

    Hello,

    I am using an AS3 typewriter script that uses a string to have a bit of dynamic text appear like it is being typed across the screen and it works great, however because the text that appears is part of a String rather than a TextField, the embedded font is not functioning.

    I have tried to combine the typewriter script together with one using a text field, however I am unable to pull off both the embedded font and the typewriter action.

    Can anyone help me to embed a font for a dynamic text that is a string?


    Here are the two scripts I'm working with:

    #1 typewriter script:

    var str:String = 'PASSING THROUGH'
    var i:uint = 0;
    var timer:Timer = new Timer (60);
    timer.start();

    timer.addEventListener(TimerEvent.TIMER,gotime);

    function gotime(e:TimerEvent) {
    textBox_txt.appendText(str.charAt(i));
    i++;
    if(i>=str.length){
    timer.stop();}
    }

    #2 embedded font script:

    var myFont:Font = new EmbeddedFont();
    var myFormat:TextFormat = new TextFormat();
    myFormat.font = myFont.fontName;
    myFormat.size = 24;

    var myTextField:TextField = new TextField();
    myTextField.autoSize = TextFieldAutoSize.LEFT;
    myTextField.defaultTextFormat = myFormat;
    myTextField.embedFonts = true;
    myTextField.text = "The quick brown fox jumped over the lazy dog.";
    addChild(myTextField);


    Thanks in advance for any insight here!

    -Llyfre

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    You need to create a new Font symbol in the library. Choose Lucida typewriter and give the class name EmbeddedFont, export for Actionscript. Then place this script in frame 1.

    var myFont:Font = new EmbeddedFont();
    var myFormat:TextFormat = new TextFormat();
    myFormat.font = myFont.fontName;
    myFormat.size = 24;

    var myTextField:TextField = new TextField();
    myTextField.autoSize = TextFieldAutoSize.LEFT;
    myTextField.defaultTextFormat = myFormat;
    myTextField.embedFonts = true;
    addChild (myTextField);

    var str:String = 'PASSING THROUGH';
    var i:uint = 0;
    var timer:Timer = new Timer(60);
    timer.start ();

    timer.addEventListener (TimerEvent.TIMER,gotime);

    function gotime (e:TimerEvent)
    {
    myTextField.appendText (str.charAt(i));
    i++;
    if (i >= str.length)
    {
    timer.stop ();
    }
    }
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Senior Member
    Join Date
    Apr 2003
    Location
    Seattle
    Posts
    177

    dynamic text x/y positions

    Thanks for combining the embedded font + typewriter scripts, didn't know simply removing the line "myTextField.text = "The quick brown fox jumped over the lazy dog.";" would do the trick.

    Problem I'm having now is that previously the dynamic text appeared in the text box called "textBox_txt" which was carefully positioned on the stage. Now however, the script is no longer associated with the what is on the stage so my text is running from the upper left corner.

    Is there a way to point the text in the string to appear in the specific textField I have created on the stage? I'd rather not use AS3 to position the X and Y of the text because I already have text boxes of a particular shape and size on the stage throughout the piece.

    Further help would be greatly appreciated!

  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    You should delete textBox_txt and position the other textfield using AS. If you really don't want then replace the part of the script with this:

    textBox_txt.autoSize = TextFieldAutoSize.LEFT;
    textBox_txt.defaultTextFormat = myFormat;
    textBox_txt.embedFonts = true;
    - The right of the People to create Flash movies shall not be infringed. -

  5. #5
    Senior Member
    Join Date
    Apr 2003
    Location
    Seattle
    Posts
    177
    Thanks cancerinform,

    I already tried replacing the script with this, however the text still doesn't appear in textBox_txt.

    textBox_txt.autoSize = TextFieldAutoSize.LEFT;
    textBox_txt.defaultTextFormat = myFormat;
    textBox_txt.embedFonts = true;


    Any other suggestions of getting the dynamic text to appear where in textBox_txt?

    Otherwise, can you please add a couple lines of AS for how to set the X and Y of the dynamic text and also give me a clue as to how I can have the text in a String drop down a line (I'm using the shape of textBox_txt to determine when the text drops down to the next line as it is now).

    I'm almost there....

  6. #6
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    I don't know what is the problem, so I attached a fla.
    Attached Files Attached Files
    - The right of the People to create Flash movies shall not be infringed. -

  7. #7
    Senior Member
    Join Date
    Apr 2003
    Location
    Seattle
    Posts
    177

    resolved!

    Thanks Cancerinform,

    It was the line:

    var myTextField:TextField = new TextField();

    that was over-riding "textBox_txt" on the stage.

    Got it all working now I think.

    Much appreciated

    -Llyfre

  8. #8
    Senior Member
    Join Date
    Apr 2003
    Location
    Seattle
    Posts
    177

    success!

    Have a look...

    Passing Through

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center