A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: counting how many letters...

  1. #1
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601

    counting how many letters...

    i'm just wondering: is it possible to show via AS the exact numbers of letters found in a variable?
    here's an example:
    Code:
    text="what are you doing?"
    here, we have 16 letters + 3 spaces.
    > what piece of script can i use to show how many letters+spaces (here16+3=19) i have?

    ...or maybe it's impossible...?

    > i'm asking because maybe i can add something like that for my current project: the longer texts are, bigger the text window is...
    i already have something like that working, but manually. so, if it can be automatic, it would be great ^^

    thanks

  2. #2
    ism BlinkOk's Avatar
    Join Date
    Aug 2001
    Location
    , location, location
    Posts
    5,002
    Code:
    text="what are you doing?"
    space=0;
    nonspace=0;
    for (i=1;i<length(text);i++) {
     c = substring(text,i,1);
     if (c == " ")
       space++;
     else
       nonspace++;
    }
    trace(space+","+nonspace);
    Graphics Attract, Motion Engages, Gameplay Addicts
    XP Pro | P4 2.8Ghz | 2Gb | 80Gb,40Gb | 128Mb DDR ATI Radeon 9800 Pro

  3. #3
    Senior Member mbenney's Avatar
    Join Date
    Mar 2001
    Posts
    2,744
    i would use the charAt() function in a similar way to blinks... if you are developing a pa system in your rpg system i added one to my zelda demo at... http://anony.co.uk/chef/zelda4.html ... use

    X to hack with sword
    SHIFT to read a sign
    SPACE to scroll the text

    this is the version i showed in my university interview but i havent worked on it since then.
    you cannot launch the stuff from the house as it works with fscommand local to the machine. i also have a browser based function written but its not uploaded and i havent changed the maps yet

    SO...what im trying to say is!... if you want some help with your PA system i will show you the code!

    [m]

  4. #4
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601
    wow, as i can see you arranged the code to look for letters and spaces separately ^^... i'll apply it to my game and see how i can work with it...

    thanks blinkOk.

  5. #5
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601
    your link is 404, mbenney.

    about it's implementation, i'm not sure of how to do it...
    what i wanted was more:
    1) calculate how many letters/spaces... well, the total lenght in fact
    2) depending on the results, launch the small, medium, big text window...

    too bad i cannot look at your example right now, i was very curious...

  6. #6
    Senior Member mbenney's Avatar
    Join Date
    Mar 2001
    Posts
    2,744
    whoopsy daisys, i referenced the wrong hosting

    http://homepage.ntlworld.com/benney.1/zelda4.html

    maybe the correct link will be better!

  7. #7
    Senior Member mbenney's Avatar
    Join Date
    Mar 2001
    Posts
    2,744
    dont want to insult your intelligence but you have considered...

    text="what are you doing?"
    trace(text.length);
    //trace gives 19

  8. #8
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601
    Code:
    trace(text.length);
    damn, where was my head? i haven't thought doing it that way.

    [quote]if you want some help with your PA system i will show you the code![quote]
    yes, thank you ^^
    i don't know how it will look like when included in my game... maybe the effect will be very cool. i already had an old file which "emulated" the typewriter effect, but your example seems better...

  9. #9
    Senior Member mbenney's Avatar
    Join Date
    Mar 2001
    Posts
    2,744
    ok bust me an e-mail if you want the source

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