PDA

View Full Version : Using a button to insert special characters into an input field


davey
02-02-2007, 03:15 AM
Hi everyone,

I'm currently on the hair-pulling roller-coaster journey that is putting an interactive crossword together, and for all intent and purposes it's been going pretty well so far. However, because it's a non-english crossword, I'd like to give the user an opportunity to insert special characters into a selected input field (the field that has focus). Currently I can display the instance name of the input field in a dynamic text field that is selected using:

word = eval(Selection.getFocus());
temp.text = word._name;

Which is fine, but what I'd like to be able to do is have a button that displays the desired character (e.g "Ä"), so that when the input field that needs a special character has focus, the user can click the button that corresponds to the letter and insert it.

The problem that I'm having is that I don't seem to be able to refer to the variable from inside a movie clip or a button, because something like this just returns an "undefined":

// displays instance fine
word = eval(Selection.getFocus());
temp.text = word._name;

// no luck here
clip.onRelease = function() {
temp.text = word._name;
}


So ultimately if that method actually worked, I'd have:

word = eval(Selection.getFocus());

clip.onRelease = function() {
_root.word._name.text = "Ä";
}

I've tried a few variations, including putting it inside a button, but nothing seems to work, just the continually demoralising "undefined." Can someone explain what I'm doing wrong?

Thanks all for your time

Dave

davey
02-08-2007, 09:18 PM
Well, I figured it out. It was a little obvious, as naturally when you click on a button after clicking in a text field it doesn't have focus any more, so what I was doing was never going to work. Instead I busted out an onKillFocus which worked a treat. The code is below if anyone's interested. This is particularly useful if you've got a large number of input fields and you want to be able to insert text in any one of them (that has focus) by clicking a button (in my case a crossword).

Thanks anyway!

Dave

onEnterFrame = function () {

word = eval(Selection.getFocus());

word.onKillFocus = function(newFocus:Object) {
_global.lastBox = this._name;
//trace("the last box was " + lastBox);
}

aSpecial.onRelease = function() {
_root[lastBox].text = "Ä";
}

}