Skip to main content
Known Participant
April 24, 2018
Answered

Using two textfield inputs to perform a function

  • April 24, 2018
  • 2 replies
  • 967 views

I would like to use two text field inputs to perform a function.

if text1.text = text2.text then gotoAndStop(2);

but its not working.

This topic has been closed for replies.
Correct answer JoãoCésar17023019

Hi.

It's been years since the last time I coded in AS2, but I think it may be what you want:

stop();

txt0.onKillFocus = function()

{

    changeFrame();

};

txt1.onKillFocus = function()

{

    changeFrame();

};

function changeFrame()

{

    if (txt0.text == txt1.text)

        gotoAndStop(2);

}

Notice that I chose to fire the comparison when one of the text fields loses focus. But you can fire the comparison using a click of a button, a loop, and so on.

Regards,

JC

2 replies

Known Participant
April 26, 2018

Quickly going back to the code you helped me with, i tried to add a button to it and on preview got a blank preview, so

what can i write to but it on a button release called go6.

go6._visible = true;

go6.onRelease = function(){

......

?

JoãoCésar17023019
Community Expert
Community Expert
April 27, 2018

Hi! I'm glad it helped you!

Hmmm... I think I'm not getting what you want.

Would you mind explaining again? Sorry about this.

Known Participant
April 27, 2018

sure okay,

i hadnt design frame(2) and got a blank page, the code you gave me worked, i went a drew a simple hello on frame (2) and because the text inputs were the same both being blank i had no control on the function and the code executed and went straight to frame (2), so i was asking if i could control it with a button, i took the code and added it to each text input seperately, and added the

  1. function changeFrame() 
  2. if (txt0.text == txt1.text) 
  3.         gotoAndStop(2); 
  4. }

to the button called go6, and still it did the same,

i tried go6.onRelease = function(){

function changeFrame()

{

if ttxt0.text == txt1.text)

gotoAndStop(2);

}

and it still just went and stoped at frame (2) without me having time to fill in the two textfields and pressing go.\

i also wanted to know this morning, the if part it has currently two text fields, could it be 4 text fields? if so how would i write in another set of two that need to match each other called txt3.text and text4.text with the

if (ttxt0.text == txt1.text)

gotoAndStop(2);

would it be

if (ttxt0.text == txt1.text);

if (txt3.text == txt4.text)

gotoAndStop(2);

those two questions ive got, and this most important, before asking to help me with :

i know i got 4 questions., the third question is : the code to add to the two buttons called go1 and go2 with txt0 and txt1,

so that once entered and the button is pressed that that a new textfield is created in a column like fashion, and next to the column the date entered in txt1 when go2 is pressed. not too big, 300 x 35, and in top left corner the first column,

and the forth question is a textinput called search and a search button called serach_btn that the text entered in the search looks in the left column only and a second one that looks in the right column text input called search_1 and ill use the same button search_btn.

dont know how you fel helping me with the four questions at once, or just the questions you can do, lets start with my first two questions if thats ok ?

Known Participant
April 26, 2018

can someone help me please,

JoãoCésar17023019
Community Expert
JoãoCésar17023019Community ExpertCorrect answer
Community Expert
April 26, 2018

Hi.

It's been years since the last time I coded in AS2, but I think it may be what you want:

stop();

txt0.onKillFocus = function()

{

    changeFrame();

};

txt1.onKillFocus = function()

{

    changeFrame();

};

function changeFrame()

{

    if (txt0.text == txt1.text)

        gotoAndStop(2);

}

Notice that I chose to fire the comparison when one of the text fields loses focus. But you can fire the comparison using a click of a button, a loop, and so on.

Regards,

JC

Known Participant
April 26, 2018

thank you very much,

very helpful and correct.