PDA

View Full Version : set focus to a textarea on combobox change


Paradise
11-01-2006, 08:49 PM
I'm having a problem with setting the focus to a textarea (myText) when a combobox change is equal to a certain value. What's happening is I'm getting a message in the output window that states:


256 levels of recursion were exceeded in one action list.
This is probably an infinite loop.
Further execution of actions has been disabled in this movie.


Any idea what the problem is here? Thanks.


var messageListenerObject:Object = new Object();
messageListenerObject.change = function(eventObject:Object) : Void {
if (myTextMessage.value == "(No message)") {
...
}
else if (myTextMessage.value == "Create a custom message") {
myText.text = "Please enter your message here.";
myTextShadow.text = "Please enter your message here.";

myText.editable = true;
myTextShadow.editable = true;

myText.depthChild0._alpha = 0;
myText.visible = true;
myTextShadow.visible = true;

myTextFontFamily.enabled = true;
myTextFontSize.enabled = true;
myTextBold.enabled = true;
myTextItalic.enabled = true;
for (i = 1; i < 10; i++)
_root["myTextColor" + i].enabled = true;

//the error occurs because the line directly below this comment
Selection.setFocus("_root.myText");
Selection.setSelection(0,0);
}
else {
...
}
};
myTextMessage.addEventListener("change", messageListenerObject);

Paradise
11-02-2006, 04:12 PM
Kind of surprised I didn't get a response to this one.

From what I can tell from the debugger "messageListenerObject.change" is getting fired when I call Selection.setFocus("_root.myText");. This is causing the looping.

My question is why is the combobox's change event getting fired when I call Selection.setFocus("_root.myText"); from within the combobox's change event?

Paradise
11-02-2006, 04:21 PM
For those of you who want a solution. It's to use doLater ... see below.

I'd still like an answer for why the combobox's change event is getting fired when I call Selection.setFocus("_root.myText"); from within the combobox's change event. Any ideas what was wrong with the previous code?


var messageListenerObject:Object = new Object();
messageListenerObject.change = function(eventObject:Object) : Void {
if (myTextMessage.value == "(No message)") {
...
}
else if (myTextMessage.value == "Create a custom message") {
myText.text = "Please enter your message here.";
myTextShadow.text = "Please enter your message here.";

myText.editable = true;
myTextShadow.editable = true;

myText.depthChild0._alpha = 0;
myText.visible = true;
myTextShadow.visible = true;

myTextFontFamily.enabled = true;
myTextFontSize.enabled = true;
myTextBold.enabled = true;
myTextItalic.enabled = true;
for (i = 1; i < 10; i++)
_root["myTextColor" + i].enabled = true;

//fix is here
myText.doLater(_root,"focusMyText");
}
else {
...
}
};
myTextMessage.addEventListener("change", messageListenerObject);

...


//Focus the myText textarea

function focusMyText() : Void {
Selection.setFocus("_root.myText");
Selection.setSelection(0,0);
}

Sunny13
11-02-2006, 04:26 PM
Insert Selection.setFocus(null);before the Selection.setFocus("_root.myText");statement and see if it works...

Paradise
11-02-2006, 04:35 PM
Thanks, that worked as well. Can you explain why and how your method works?

Sunny13
11-03-2006, 02:16 PM
actually i have done some work with setFocus some times ago and we found the same problem.. may be a bug but not sure and then we came up with this solution...