Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to retrieve this value??? 1

Status
Not open for further replies.

Sleidia

Technical User
May 4, 2001
1,284
FR
Hi everyone ! :)

Can someone tell me why I can get the value from my text field when the enter key is pressed? I guess I don't use the right statement to get the value.


mc_new_mess = new Object();

mc_new_mess.onKeyDown = function() {

if (Key.getCode() == Key.ENTER) {

test_var = "xxxxxxxxx" // outputs xxxxxxxxx in the other field
test_var = this.ins_new_mess.text; // outputs nothing in the other field
test_var = ins_new_mess.text; // outputs nothing in the other field
test_var = mc_new_mess.ins_new_mess.text; // outputs nothing in the other field

} else {

}

}

Key.addListener(mc_new_mess);
 
I don't see where you are collecting any data from a text field.

What is the name of the field you are trying to collect data from? ins_new_mess?

I think you have just overcomplicated. Try this:

Code:
mc_new_mess = new Object();

mc_new_mess.onKeyDown = function() {
	var txtBox = this.ins_new_mess.text;//if this is the instance name and location of your textbox
    this.test_var = txtBox;

	/*test_var = "xxxxxxxxx" // outputs xxxxxxxxx in the other field
    test_var = this.ins_new_mess.text;    // outputs nothing in the other field
    test_var = ins_new_mess.text;    // outputs nothing in the other field
    test_var = mc_new_mess.ins_new_mess.text;    // outputs nothing in the other field*/
    
}

InstanceNameofButton.addEventListener("onKeyDown", mc_new_mess);

Hope it helps.

Wow JT that almost looked like you knew what you were doing!
 
Hi again pixel8r :)

First, this way of doing things is supposed to work ;)
It is supposed to retrieve some text from a text field after the user has hit the ENTER key in it. The retrieved value is then displayed in another field (test_var) for testing purpose (it will go to a database when it works).

Still, I have no clue about how I could retrieve the value of the instance ins_new_mess (found in the movie clip mc_new_mess) and send it to test_var.

Here is another site where I've posted the same message but unfortunately, the kind replies didn't put me in the right track :
Thanks for your response anyway.
 
First, this way of doing things is supposed to work ;)
It is supposed to retrieve some text from a text field after the user has hit the ENTER key in it. The retrieved value is then displayed in another field (test_var) for testing purpose (it will go to a database when it works).

I didn't suggest that the way of doing it was not supposed to work. Obviously your implementation is incorrect (if it isn't working) or you would not need assistance.

After reading your post on Actionscript.org I understand a little better. It would have been very helpful if you would have posted that information here so you could better be assisted.

As I understand it you have a movieclip on the main timeline with the instance name "mc_name_mess". Within that MC you have a text input field with the instance name "ins_name_mess". If that is correct and your actionscript is on the main timeline (as opposed to the mc_name_mess timeline) it will not work.

Secondly you have named the listener object the same as a MC instance on the stage. Bad. Use a unique name. The following should be placed on the first(only) frame of the mc_new_mess timeline.

Code:
myListener = new Object();

myListener.onKeyDown = function() {

    if (Key.isDown(Key.ENTER)){
		trace("You entered "+ ins_new_mess.text);
	}
}

Key.addListener(myListener);

That will work.

Hope it helps,

Wow JT that almost looked like you knew what you were doing!
 

Hello pixel8r :) !

Many thanks for the help !
What I've figured out before I read you message was that, as you said, the code concerning the movie clip mc_new_mess needed to be placed on the right timeline and not on the main timeline like I did (which I find stupid because, anyway, the references to all objects have a path such as : _root.mc_new_mess.ins_new_mess.text ).

So, the follwing code works when found inside the timeline of the movie clip mc_new_mess :
Code:
mc_new_mess = new Object();

mc_new_mess.onKeyDown = function() {

	if (Key.getCode() == Key.ENTER) {

	_root.ins_test_var.text = _root.mc_new_mess.ins_new_mess.text + "zzzzzzzzzzz";
	
	} else {

	}

}

Key.addListener(lis_new_mess);

But I've added some code on the top of the one above as follow :

Code:
_root.mc_new_mess.ins_new_mess.text = "Type your text here";
_root.mc_new_mess.ins_new_mess.focusEnabled = true;
Selection.setFocus(_root.mc_new_mess.ins_new_mess);
Selection.setSelection(0, _root.mc_new_mess.ins_new_mess.length);

This code works nicely : it tells the user where to type the text by putting a selection on the warning "Type your text here" in ins_new_mess .

The problem is that the third line of code will prevent the
value to be passed on to the other field when ENTER key is pressed. Once I comment the third line everything works but without the text to be selected.

I'd be glad to hear your opinion about that :)

Have a nice day !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top