A few suggestions: > I have a fill-in-the-gaps exercise and I have added a hint > button which checks to see which part of the word a student > has entered is correct and then adds the next (correct) > letter to the end of the string. My problem is that the > cursor stays just in front of the added letter instead of > going to the end of the string. I've tried selecting the > letter that has just been added and for a second the last > letter is highlighted but then the cursor goes back to its > original place. Here's the code I'm using: > > function showLetter() { > //get the text the student has entered > currentWord = eval("gap"+currentGap).gap_txt.text;
using Eval here is a bit out of date - try currentWord = this["gap"+currentGap].gap_txt.text > currentLength = currentWord.length; > newText = ""; > correctText = gWords[currentGap]; > lastLetter = 0; > //compare it one letter at a time to the correct answer > for (j=0; j<currentWord.length; j++) { make sure you use 'var j=0' here, otherwise you could cause problems elsewhere in your code (in fact, you may need to do this with several other variables here, including lastLetter, newText and correctText) > if (currentWord.charAt(j) == correctText.charAt(j)) { > newText += correctText.charAt(j); > lastLetter = j; > } else { > break; > } > } > currentLength = newText.length; > //show the correct portion of the text plus the next > (correct) letter > eval("gap"+currentGap).gap_txt.text = again, this["gap"+currentGap].gap_txt.text = > gWords[currentGap].substr(0, currentLength+1); > eval("gap"+currentGap).gap_txt.setTextFormat(numFormat); > //select the last letter - this does not move the cursor > Selection.setSelection(currentLength,currentLength+1); Now, when is this happening? If it's on a keyDown, you might want to think about doing it on an onChanged event instead. Danny _______________________________________________ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com