Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6993099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:43:14+00:00 2026-05-27T19:43:14+00:00

Given the following example SWF: Sample Notice how with the words enthusiast at the

  • 0

Given the following example SWF:
Sample

Notice how with the words “enthusiast” at the end of the first line and “write” at the end of the second line, that they start to type out on the first line but after a few letters they are bumped.

I understand this is the correct behavior, but is there a way for “enthusiast” to begin being typed on the second line, and “write” on the third line instead of being bumped during the typing?

Currently I am thinking of doing a search ahead mechanism, so it finds the next word in whole, then makes that the active word to print, temporarily print it, see if it increases the numlines, and if it does insert a line break and continue writing. But it seems fiddly.

Code below:

import flash.text.TextField;
import flash.events.Event;

var tt:TextField = new TextField();
tt.wordWrap = true;
tt.width = 200;
tt.height = 50;
tt.border = true;

var s = "Stack Overflow is for professional and enthusiast programmers, people who write code because they love it. We feel the best Stack Overflow questions have a bit of source code in them, but if your question generally covers";
addChild(tt);

var currentLetter:int = 0;

addEventListener(Event.ENTER_FRAME, onEnter, false, 0, true);

function onEnter(e:Event):void 
{
    if(currentLetter < s.length)
    {
        tt.appendText(s.charAt(currentLetter));
    }
    currentLetter++;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:43:15+00:00Added an answer on May 27, 2026 at 7:43 pm

    adjusted your code a bit and posted the result on wonderfl: http://wonderfl.net/c/rZkm

    as @mouseas suggested i put the next word into an additional textfield measure the width and compare this to the remaining space in the current line … if the next word doesn’t fit I add a line-break and continue.

    here’s the code:

    package {
        import flash.geom.Rectangle;
        import flash.text.TextFieldAutoSize;
        import flash.display.Sprite;
        import flash.text.TextField;
        import flash.events.Event;
    
        public class FlashTest extends Sprite {
    
            private var currentLetter:int = 0;
            private var tt:TextField;
            private var debug:TextField;
            private var pre:TextField;
            private var s:String;
    
            public function FlashTest() 
            {
                // write as3 code here..
                tt = new TextField();
                tt.wordWrap = true;
                tt.width = 200;
                tt.height = 150;
                tt.border = true;
    
                s = "Stack Overflow is for professional and enthusiast programmers, people who write code because they love it. We feel the best Stack Overflow questions have a bit of source code in them, but if your question generally covers";
                addChild(tt);
    
                // predraw word
                pre = new TextField();
                pre.y = 150;
                pre.width = 200;
                pre.height = 50;
                pre.autoSize = TextFieldAutoSize.LEFT;
                pre.border = true;
                addChild(pre);
    
                // debug txt
                debug = new TextField();
                debug.x = 250;
                debug.wordWrap = true;
                debug.width = 200;
                debug.height = 500;
                debug.border = true;
                addChild(debug);
    
                addEventListener(Event.ENTER_FRAME, onEnter, false, 0, true);
            }
    
            private function onEnter(e:Event):void 
            {
    
                //debug.appendText("char: " + rect.x + " " + rect.width + "\n");
                var c:String = "";
                if (currentLetter < s.length)
                {
                    c = s.charAt(currentLetter);
                    tt.appendText(c);
                }
                else
                {
                    debug.appendText("DONE! \n");
                    removeEventListener(Event.ENTER_FRAME, onEnter);    
                }
    
                if (c == " ")
                {
                    var rect:Rectangle = tt.getCharBoundaries(currentLetter-1);
                    if (rect != null)
                    {
                        //debug.appendText("char: " + rect + "\n");
                        var cPos:int = rect.x + rect.width;
                        var r:int = tt.width - 4 - cPos;  // 4px for gutter on left+right side of textfield 
    
    
    
                        var start:int = s.lastIndexOf(" ", currentLetter);
                        var end:int = s.indexOf(" ", currentLetter+1);
                        if (start < 0) start = 0;
                        pre.text = s.substr(start, end-start);
    
                        debug.appendText("rest: " + r + " " + pre.textWidth + " > " + pre.text + "\n");
    
                        if (r - pre.textWidth <= 0)
                        {
                            tt.appendText("\n");
                            debug.appendText("\n");
                        }
    
                        //debug.appendText("w:" + tt.textWidth + " " + start + "->"+ end + " /" + pre.text + "/ " + pre.textWidth + "\n");
                    }
                }
    
                ++currentLetter;
            }
        }
    }
    

    works great – only the “a” in the 4th line makes trouble – maybe you need to finetune the calculations a bit…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following example data: Users +--------------------------------------------------+ | ID | First Name | Last
Given the following HTML example... <div id='div1'>div one</div> <div id='div2'>div two</div> ...I found that
Given the following example: class AnonymousSession << Struct.new(:location, :preferences) def valid? ... end def
Given the following example: http://jsfiddle.net/A8v9x/4/ - when you click the first link and then
Given the following example (using JUnit with Hamcrest matchers): Map<String, Class<? extends Serializable>> expected
In the following contrived example, data is given a warning due to it being
This is just an example, but given the following model: class Foo(models.model): bar =
Given a group of files with the following naming convention: datetime_restofname.txt an example of
How can you sort the following word by the given rule? Example data is
I need a regex that will give me the following results from each example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.