A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: counting words in text field

  1. #1
    Senior Member
    Join Date
    Jul 2002
    Location
    New Mexico
    Posts
    101

    counting words in text field

    is it possible to count the amount of words in a dynamic text field in flash 8?

    thanks
    Beyond Flash
    Your one stop web shop
    http://www.beyondflash.net

  2. #2
    Senior Member Robb@exo's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    1,540
    This works, although I'm not sure it would in every instance.
    Actionscript Code:
    dt.text = "this is just a test to see if counting the words in a dynamic text can be done.";

    b.onRelease = function() {
        for(var i = 0; i < dt.text.length; i++) {
            String.prototype.countChars = function(arg) {
                return this.split(arg).length - 1;
            };
            str = dt.text;
            num = str.countChars(" ");
            words = num + 1;
        }
        trace("There are " + words + " words.");
    }
    Wile E. Coyote - "Clear as mud?"

  3. #3
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    another way is:

    Code:
    myText = "this is just a test to see if counting the words in a dynamic text can be done."
    
    trace("the number of words: "+ myText.split(" ").length);
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

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