A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: why does this script stop working after the 1st loop?

  1. #1
    Senior Member
    Join Date
    Apr 2002
    Location
    Saginaw, MI
    Posts
    185

    why does this script stop working after the 1st loop?

    1st Frame:
    myString = "anonymous";
    2nd Frame:
    _root.word.text = myString;
    if (myString.lastIndexOf(String.fromCharCode(Key.getA scii())) == myString.length-(myString.length)) {
    myString = myString.slice(1, myString.length);
    }
    3rd Frame:
    gotoAndPlay(2);

    after u type the letter "a", it doesn't respond to any keypress. anyone kno y this would b?
    I am determined to make better mistakes tomorrow.

  2. #2
    Senior Member
    Join Date
    Jul 2000
    Posts
    243
    What do you mean it doesnt respond to any keypress?

    I made up a small one just like you have and I can type in it.?

    Explain

  3. #3
    Senior Member
    Join Date
    Apr 2002
    Location
    Saginaw, MI
    Posts
    185
    ok, when i test it, i can type the first letter "A" and the code works, but when i try to type the next letter "N", it doesnt do anything. and i even set it up so that a message would a appear when the first if statement (myString.lastIndexOf(String.fromCharCode...) is fulfilled, and that doesnt work! im not sure wuts wrong... could u send me the one that u set up?
    I am determined to make better mistakes tomorrow.

  4. #4
    The ActionScript Master Master64's Avatar
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    654
    Would
    code:

    myString = "anonymous";
    myString = myString.slice(1, myString.length);
    trace(myString)
    //traces: ""




    ??????
    Master64
    useing:XP,MX

    don't send me PM's because i never check it so if you what to contact me use Email

  5. #5
    Senior Member
    Join Date
    Jul 2000
    Posts
    243
    so your trying to get it to remove a ltter with a letter is presses?

  6. #6
    Senior Member
    Join Date
    Apr 2002
    Location
    Saginaw, MI
    Posts
    185
    i want the user to press the key that corresponds with the first letter of the word, on the key press i want that letter to be removed and then the user will hav to press the next key until the word is gone
    I am determined to make better mistakes tomorrow.

  7. #7
    Former Member now elsewhere
    Join Date
    Dec 2001
    Location
    Out of here
    Posts
    104
    Ok. I'd approach this in a single frame:

    //You set the value for the string
    myString = "anonymous";

    //Then you replaced it with input text
    _root.word.text = myString;

    // This code I'm not following too well but I think you did
    // length-length which is always 0. If that's true then you slice.
    // This is your original:
    if (myString.lastIndexOf(String.fromCharCode(Key.getA scii())) == myString.length-(myString.length)) {
    myString = myString.slice(1, myString.length);
    }

    // What about something like this (my syntax may be wrong here!!
    // But you can get an idea of the approach)

    while(mystring.length>0){
    onClipEvent(keydown){
    if(mystring.index[0]==Key.getAscii){
    myString = myString.slice(1, myString.length);
    }
    }
    }

    That the idea?
    NCD

  8. #8
    Senior Member
    Join Date
    Apr 2002
    Location
    Saginaw, MI
    Posts
    185
    no im sorry... its still not working. i dont get it, my code works with some word like "abcdefghijklmnopqrstuvwxyz" but not "anonymous". can anyone figure this out?
    I am determined to make better mistakes tomorrow.

  9. #9
    Senior Member
    Join Date
    Apr 2002
    Location
    Saginaw, MI
    Posts
    185
    hey im not sure if anyone cares but i found out how to do it

    if (Key.getAscii() == myString.charCodeAt(0)) {
    myString = myString.slice(1, length);
    }

    thank you all!
    I am determined to make better mistakes tomorrow.

  10. #10
    Senior Member
    Join Date
    Jul 2000
    Posts
    243
    Cool!! Thanks for posting that you fixed it and thanks for posting the script that fixed it. Its good to not leaving us hanging

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