AS3: Text field boundaries

I have 2 dynamic textfields (elderText, youngText) that I added a vertical scroll bar to and it works great.
When I add and remove the text fields a few times (runtime) the line breaking of the textfields changes and the scrolling becomes horizontal (the textfield, not the scroll bar).
I want to make sure the text will break properly and will not cross the field horizontal boundaries at all!!
The problem started after I added the scroll bar:
var bounds:Rectangle = new Rectangle(scrollMC.x, scrollMC.y, 0, 225);
var scrolling:Boolean = false;
function startScroll (e:Event):void {
    scrolling = true;
    scrollMC.startDrag (false,bounds); 
function stopScroll (e:Event):void {
    scrolling = false;
    scrollMC.stopDrag ();
scrollMC.addEventListener (MouseEvent.MOUSE_DOWN, startScroll);
stage.addEventListener (MouseEvent.MOUSE_UP, stopScroll);
scrollMC.addEventListener(Event.ENTER_FRAME, enterHandler);
function enterHandler (e:Event = null):void {
    if (scrolling == true) {
        if (Boolean(getChildByName('elderText'))){
            elderText.scrollV = Math.round(((scrollMC.y - bounds.y)/225)*elderText.maxScrollV);
        if (Boolean(getChildByName('youngText'))){
            youngText.scrollV = Math.round(((scrollMC.y - bounds.y)/225)*youngText.maxScrollV);

elderText.wordWrap = true;
youngText.wordWrap = true;
I added these lines and it solved the problem.
Can I check if the text field is big enough to contain the whole text?
In other words can I check if scroll bar is needed or not?
Thanks for the help.

Similar Messages

  • Auto-tabbing between input text fields in AS3

    Hello-
    I am having some trouble figuring out how to work auto-tabbing between input text fields when a user inputs a character. I have a series of text boxes with maxChar set to 1, and when the user inputs a character, I would like it to auto-tab to the next one. I'm putting together a crossword-style banner ad so the auto-tabbing will help tremendously.  All the input text fields are instanced on the stage as input1, input2, etc; not called in from a custom class.  Also, I've been working with AS3 for about 2 weeks lol!
    thanks!

    Awesome, thank you, that works nicely! Now I need to figure out how to capture individual keyCodes for each input and then come up with a conditional to check for right or wrong answers. I have a "check your answers" button all set up. I think I am almost there, possibly a syntax hiccup for me. Any advice on how to do that would be appreciated.

  • Placing cursor in text field using AS3

    I am a newbie to actionscript 3.0 and need a litlle help that I have not been able to find searching (for two weeks).
    I would like the cursor to appear and blink in the first text field in  a  movie clip that gathers information to be sent to a php. The  following  does not work.
    stage.focus = textField;
    textField.setSelection(textField.text.length,textF  ield.text.length);
    And the only other things I find are for custom cursors. I just want  the  visitor to see the blinking cursor in the firstName_txt input box  when  the page appearss.
    Also, if the visitor tabs from one  input text field to the other, the blinking  cursor appears in the first  three input text fields but not in the fourth.  Yet, the visitor can  enter text in the fourth input text field.

    I have tested by clicking crtl+enter and uploaded the files to my isp for testing. Neither effort is successful.
    BTW, thanks for helping and I am sorry about the cross posting. My bad. I didn't realize there was a section for actionscript at the time.

  • AS3: How to get height of a dynamically created text field

    I am importing text from an XML file and want the lines of text to display in separate text fields beneath each other. How can I set the y value of each succeeding text field so that there is some space (40 pixels or so) from the above field, regardless of the length of the text? Here is my current code. Any help would be greatly appreciated.
    var textArray:Array = new Array();
    for (var i:int; i <myXML.TOPIC[0].QUERY.length(); i++) {
    var textField:TextField = new TextField();
    textField.htmlText = myXML.TOPIC[0].QUERY[i].QUESTION;
    textField.x = 100;
    //below is my problem....I want the y value to be based on the height of all the previous text fields that have been created
    textField.y = 100+(40*i);
    textField.border = true;
    textField.width = 800;
    textField.textColor = 0x000000;
    textField.multiline = true;
    textField.wordWrap = true;
    textField.selectable = false;
    addChild(textField);
    textArray.push(textField);

    There's nothing wrong with the approach you took... retain it as is.  What I was suggesting is basically the same, just a slightly different angle that doesn't need the conditional....
    var currentY:Number = 100;
    for (var j:int = 0; j <myXML.TOPIC[0].QUERY.length(); j++) {
       textArray[j].y =  currentY;
        // text gets added somewhere in here
        currentY =  currentY+textArray[j].height+5;

  • Using AS3 to create a random quotes in text field

    Hi,
    I though this would work but unfortunately I am not pulling the txt files into the field.
    It is definitley giving me random feedback.
    There are ten quotes in a folder: Suzuki_quotes/quote1.txt etc
    Should I not use a Dynamic Text field and create a text field using the var.
    Thanks
    stop();
    var randomNumber:Number = Math.ceil(Math.random()*10);
    var reqB:URLRequest=new URLRequest("Suzuki_quotes/quote1.txt");
    var loaderB:URLLoader = new URLLoader();
    function textLoadedB(event:Event):void {
        quoteLdr.text ="Suzuki_quotes/quote"+randomNumber+".txt";
    loaderB.addEventListener(Event.COMPLETE, textLoadedB);
    loaderB.load(reqB);
    btn1.addEventListener(MouseEvent.CLICK, goPage2);
    btn2.addEventListener(MouseEvent.CLICK, goPage1);
    function goPage1(evt:MouseEvent):void{
        gotoAndStop("page1");
    function goPage2(evt:MouseEvent):void{
        gotoAndStop("page2");

    if  you have several txt files each with one quote, try:
    stop();
    var randomNumber:Number = Math.ceil(Math.random()*10);
    var reqB:URLRequest=new URLRequest("Suzuki_quotes/quote"+randomNumber+".txt");
    var loaderB:URLLoader = new URLLoader();
    function textLoadedB(event:Event):void {
        quoteLdr.text =event.target.data;
    loaderB.addEventListener(Event.COMPLETE, textLoadedB);
    loaderB.load(reqB);
    btn1.addEventListener(MouseEvent.CLICK, goPage2);
    btn2.addEventListener(MouseEvent.CLICK, goPage1);
    function goPage1(evt:MouseEvent):void{
        gotoAndStop("page1");
    function goPage2(evt:MouseEvent):void{
        gotoAndStop("page2");

  • Linking a class to a dynamic text field to load XML data.

    Hi,
    I'm quite new to ActionScript and would be grateful for any help here.
    I want to load text into a dynamic text field (called 'about_tab') using  a class depending on the language selected (by clicking on a flag icon)  by the user.
    I managed to get this to work when the ActionScript was written directly  in the timeline, but am having problems with doing the same thing via a  class.
    This is my class file:
    package
    import flash.display.SimpleButton;
    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    import flash.net.URLRequest;
    import flash.net.URLLoader;
    import flash.events.Event;
    public class ChangeLang extends SimpleButton
    public function ChangeLang()
    addEventListener(MouseEvent.CLICK, switchLang);
    trace("ChangeLang class working");
    public function switchLang(event:MouseEvent):void
    var lang = event.target.name;
    var req:URLRequest = new  URLRequest("languages/"+lang+".xml");
    var loader:URLLoader = new URLLoader();
    var substance:XML;
    function xmlLoaded(event:Event):void
    trace("function xmlLoaded is running");
    substance = new XML(loader.data);
    about_tab.text =  substance.about_lbl;
    loader.addEventListener(Event.COMPLETE, xmlLoaded);
    loader.load(req);
    Here's one of my XML files (the other is the same except "About" is  written in German):
    <substance>
    <about_lbl>About</about_lbl>
    </substance>
    When I run it, it returns my trace statements that the class ChangeLang  and the function xmlLoaded are running, but no text appears in the  dynamic text field (I should/want to see the word 'About'). I get this  error message:
    1120: Access of undefined property about_tab
    The problem, I'm guessing, is in the part in red in my code. I think I need to target the text field in the display list by creating a  reference to it. If so, could someonw point out how I do this, or perhaps a tutorial that would help. I've tried adding the word stage (i.e.,stage.about_tab.text =  substance.about_lbl; ) but it still doesn't connect. I guess there's something really simple I'm missing, so I  apologize if this comes across as a stupid question
    Thanks for any help.

    Hello flashrocket!
    I'm also new to AS3 and I've just started using external classes and I think I know what you should do to put your code to work.
    Instead of using the text field you created inside your flash file, why don't you use the "TextField" class to create an instance of this object? It's the exact same thing as when you create and instantiate a new text field inside Flash.
    First, import flash.text.*; (includes classes like TextField, TextFieldAutoSize, TextFormat, TextFormatAlign, etc)
    Than you just have to create a var like
    public var about_tab : TextField;
    or
    public var about_tab : TextField = new TextField();
    then, to adjust the properties of this tab you use dotsyntax as if it where on your stage like:
    about_tab.x = 50; about_tab.alpha = .5; etc...
    you can even create a function to "config your textField"
              private function createAndConfigTextField() : void {
                   about_tab = new TextField(); //you only need this line if you
              // only typed something like "public var about_tab:TextField;
              // if instead you used "public var about_tab:TextField = new TextField(); outside
              // this function, just skip this first line because you already have an instance of
              // text field named "about_tab"...
                            about_tab.autoSize = TextFieldAutoSize.CENTER;
                   about_tab.background = true;
                   about_tab.border = true;
                   var aboutTextFormat : TextFormat = new TextFormat();
                   format.font = "Arial";
                   format.color = 0x000000;
                   format.size = 11;
                   format.bold = true;
                   format.align = TextFormatAlign.CENTER;
                   about_tab.defaultTextFormat = aboutTextFormat;
                   addChild(about_tab);
    This is just an example of what you can do... I hope you get it... let me know if you have any doubt...

  • Using a rich text editor to style a Flash text field

    I've been trying to build a user interface that would allow someone to change the content of a dynamic field (loaded from a text file) using a rich text editor. However the editor inserts inline css style tags like <span style="text-decoration: underline;"> which Flash aparently can't understand. If the editor were instead to insert the following: <span class="ul"> where the stylesheet defined it as:
    .ul {
    text-decoration: underline;
    display: inline;
    then everything would be fine. But it doesn't and I can't change it.
    I am currently using a rich text editor that I access as follows:
    var myEditor1 = new YAHOO.widget.SimpleEditor('editText', {
        height: '600px',
        width: '700px',
        dompath: true, //Turns on the bar at the bottom
        handleSubmit: true
    The editor above is "applied" to a textarea within an html form. Then the text is saved to a text field with the embeded styles.
    Any ideas on how I handle this so the user doesn't have to insert css rules by hand?
    thanks much

    Does anyone know of a richtext editor that uses just html tags (not css like <span style="text-decoration: underline;">) or that uses css styling that Flash as3 can understand?

  • Dynamic Text Field

    I've created a dynamic text field where I've insert into a lot of HTML code.
    Since it's too much long I've used a default scrollbar and simply dropped it onto the field so that It's linked to that.
    When I try it the bar is there but I can just see the upper arrow and the bottom one; the middle part isn't visible and I can't scroll down the HTML content.
    Any idea?

    It's possible it will work in AS3 since I just tried it 1) didn't kick up an error, and 2) worked (using your code, so I don't know what your problem really is).
    That's the trouble with having languages that allow similar things to be coded differently... it can sometimes be hard to tell.  It's bad enough there are usually numerous ways to approach a design.
    If I were setting an autoSize I would be using (based on the help docs)...
    links.autoSize = TextFieldAutoSize.LEFT;

  • AS3 text problem

    Hi,
    Just playing with some AS3; and encountered the following
    problem (CODE IS ATTACHED):
    Wanted to create a MC button I seen done on the
    gotoandlearn.com site, but wanted to change it from AS2 to AS3;
    Everything works fine, but where I am assigning a value to a
    dynamic text field it not working.
    b1_mc.buttText_mc.buttonText_txt.text = "Lynda.com";
    When I test movie, lynda.com is the text on my MC button, but
    Upon ROLL_OVER etc... it displays the test text, not
    Lynda.com.
    Can someone please help me out here. It would be appreciated.
    Kind Regards,
    Boxing Boom

    Hi,
    Yes. Well spotted. I had the instance name of buttText_mc,
    missing the _mc part on a few frames with motion tweens applied, on
    the button animation. I do not remember renaming it differently ;)
    - must blame tools ;)
    Kind Regards,
    Boxing Boom

  • Difficulty displaying numeric info in text field

    I'm trying to display the playheadTime of an FLV movie
    (called vid_player) on the stage in a test field (called
    myTextField). I used to be able to do this in older actionscript,
    but with AS3, I'm having a heck of a time. Here's my code:
    function getCurrentTime(evt:MouseEvent):void {
    var currentTime:Number = this.vid_player.playheadTime;
    this.myTextField = currentTime;
    step3Tab.addEventListener(MouseEvent.CLICK, getCurrentTime);
    I get this error:
    1067: Implicit coercion of a value of type Number to an
    unrelated type flash.text:TextField.

    I don't think you've quite been able to do this in previous
    versions! The error is telling you exactly what is wrong. You are
    trying to change a TextField into a Number and that just won't
    work.
    I haven't done enough with AS3 to be sure off the top of my
    head if it changed or not, but I think you want the text or the
    htmlText property of the text field.
    this.myTextField.text=currentTime;
    or if it doesn't like that you may need to cast or convert
    the currentTime to a string;
    this.myTextField.text=String(currentTime);
    this.myTextField.text=currentTime.toString();

  • Error checking input text fields.

    Hi
    Just wondering where I find a list of what can be error checked in input text fields?
    I'm looking for things like...
    - checking that letters and not numbers are entered
    - checking that an entered number is in a certain range
    etc...
    Thanks guys
    Shaun

    To restrict input for a text field, use the following AS3 codes:
    myInput.restrict = "A-Z, a-z, ., ,'"; //myInput is the instance name of your text area
    To check the range of the numbers, use the following code:
    myInput.restrict = "0-9";
    myInput.maxChars = 3;
    myBtn.addEventListener(MouseEvent.CLICK, chk);
    function chk(e:MouseEvent):void
        var myString:String = myInput.text;
        var i:Number = Number(myString); //Converting the string to a number variable
        var max:Number = 100; //Maximum range
        var min:Number = 30; //Minimum range
        if (i < max && i > min) //Condition to indicate the range
            trace("Within range");
        else
            trace("Out of range");
    Hope this helps.

  • Creating Dynamic Text Field for Flash CS3 in Illustrator CS3

    I've created a series of buttons in an illustration and made
    them into movie clip symbols in Illustrator. I then created some
    text fields for the button labels and assigned them as dynamic text
    in the Flash Text panel in Illustrator.
    When I import the illustration into Flash and test the movie,
    I get this error message:
    TypeError: Error #1034: Type Coercion failed: cannot convert
    flash.text::TextField@d18cef9 to flash.display.MovieClip.
    at
    flash.display::Sprite/flash.display:Sprite::constructChildren()
    at flash.display::Sprite$iinit()
    at flash.display::MovieClip$iinit()
    at menu2_fla::MainTimeline$iinit()
    It seems like Flash is misinterpreting the text fields
    brought in from Illustrator as Movie Clips?

    Download the TinkSpark source from http://code.google.com/p/tink/source/checkout and add the package to your project:
    Then write the following code:
    import ws.tink.core.Library;
    import ws.tink.events.LibraryEvent;
    import ws.tink.managers.LibraryManager;
    private function loadLibrary():void
         var library:Library = LibraryManager.libraryManager.createLibrary( "assetsLibrary" );
         library.addEventListener( LibraryEvent.LOAD_COMPLETE, onAssetsLibraryLoadCompleteHandler, false, 0, true );
         library.loadSWF("board.swf" ); //provide the path of board.swf, pls note board.swf is alos exported as AS3.0
    private function onAssetsLibraryLoadCompleteHandler( event:LibraryEvent ):void
        EventDispatcher( event.currentTarget ).removeEventListener( event.type, arguments.callee );
        var library:Library = LibraryManager.libraryManager.getLibrary( "assetsLibrary" );
        var AssetScore:Class = library.getDefinition( "Score" );
        var score:* = new AssetScore() as Sprite;
        score.scoreDisplay.text = "100";
        addChild( score );
    Warm Regards
    Deepanjan Das
    http://deepanjandas.wordpress.com/

  • Input text field displays U.S. keyboard layout

    Hi,
    I've got a Flash Player 9 / AS3 animation which has a input
    text field where a user enters their email address.
    Now my PC is setup to use the UK keyboard layout so when I
    click the buttons Shift+@ then I get the @ symbol displayed.
    But for some reason the moment I try typing in the @ symbol
    (using Shift+@ keys) then up pops the " symbol which is a U.S.
    keyboard layout if I'm not mistaken?
    And so checking this, if I use the Shift+number 2(") key then
    I get the @ symbol (which again is a U.S. keyboard layout if I'm
    not mistaken?).
    Obviously I can't expect my UK users to know this and so need
    to work out how to change the keyboard layout for the text input
    fields so when I click the shortcut buttons Shift+@ I should see
    the @ symbol appear.
    Hope that all makes sense.
    Any help is greatly appreciated as this is a live project
    that the client is racing to get fixed.
    Many thanks and kind regards,
    Mark

    Hi,
    I have found some other weird things happening regarding this
    issue which are very odd?
    To recap....
    If I type into the search bar at the top of this page Shift+@
    then I get the correct character displayed which is @ (so my
    keyboard is definitely UK layout).
    If I create a new Flash movie with nothing but a text field
    set to INPUT and type Shift+@ then again I get the correct
    character!
    But if I type Shift+@ into my Flash movie I get the wrong
    character " appear!?
    I then checked both text fields and found there were
    absolutely no differences (except for colour/font size), so I
    copied the new text field into my Flash movie and the moment I
    played my Flash movie the new text field (which was working) then
    started doing the same and displaying the wrong character???
    Any ideas?
    Thanks.
    Kind regards,
    Mark

  • Using a button to check an input text field

    I am an educator and I am designing an interactive activity for my students. I created two buttons named button_B and button_G, and an input textfield named in_Text.  When a student presses button_B, the letter "B" is entered into the input text field; if a student presses button_G, the letter "G" is entered into the input text field. More than one letter entry is acceptable as a student's answer: for exmple the entry BBB, BGB within the input field is okay.  I have no trouble writing AS3 to accomplish this task, however:
    For a student's solution to the input text field to be correct, it has to contain the four values BBB, GGG, BGB, and GBG in any order. I created an array named solution_S with these values. I also have an enter the solution button named enter_btn. The student can check their solution by pressing the enter_btn button; if the input textfield is correct, the quiz moves on to the next frame in my timeline; if it is incorrect, it moves to a different frame in my timeline. How would I enter this actionscript to accomplish this? Thanks much!

    var check:Boolean=false;
    for(var i:uint=0;i<solution_S.length;i++)
      if( solution_S[i].toString()==in_Text.Text)
    check=true;}
    if(check)
    gotoAndStop(...);
    else
    gotoAndStop(...);

  • Text field link

    I need to add a paragraph to a flash file. How can I make a
    word in the text field paragraph link to a separate frame in the
    time line? thanks

    If there is a method for applying timeline commands to words
    in static text, I don't think it would be any less time consuming
    than using invisible buttons over the words, possibly moreso since
    you have to code for each word anyways. AS3 does make button event
    coding a bit more time consuming though.
    AS1/AS2 would make it alot quicker to do this because you can
    simply copy (or reuse) a button and resize it for the word and just
    change the frame number or function call for the code attached to
    the button.

Maybe you are looking for