• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Compare two word

Contributor ,
Mar 01, 2015 Mar 01, 2015

Copy link to clipboard

Copied

I need to compare two word in two different text.

I use the "if" condition, for exemple:

  if (MytextA == MytextB)

  {

  trace("==");

  }

else

{

  trace("!=");

}

But I suppose == and !== is a wrong method for text and my purpose.

Can you help me?

Thank you.

TOPICS
ActionScript

Views

414

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 01, 2015 Mar 01, 2015

Copy link to clipboard

Copied

If MytextA and MytextB are the names of the two textfields, you need to test their text properties...

  if (MytextA.text == MytextB.text)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 01, 2015 Mar 01, 2015

Copy link to clipboard

Copied

Thank you Ned,

of course! I write it in my post a short form,

but also " if (MytextA.text == MytextB.text)" doesn't work.

Thank you again.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 01, 2015 Mar 01, 2015

Copy link to clipboard

Copied

It should.  Explain what you have done on the stage for what you call MytextA and MytextB

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 01, 2015 Mar 01, 2015

Copy link to clipboard

Copied

Thanks Ned!

On the stage I have two texts that I change dinamically  with two button. 

With this two buttons  I assign different world to text on the stage.

At some points I need to compare two text but as I say before the result is always !== also when both texts contains the same words.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 01, 2015 Mar 01, 2015

Copy link to clipboard

Copied

I don't know what you might have done that causes it to not work properly... maybe you have things on different frames or something.  Here is a link to a quick example file I made for you to look at.  Run it and click the button to have the texts change and get compared.

http://www.nedwebs.com/Flash/AS3_compare_text.fla

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 02, 2015 Mar 02, 2015

Copy link to clipboard

Copied

Make sure both fields are set to singleLine or MultiLine... if one is single line and the other multiLine you will get false when it should be true.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 08, 2015 Mar 08, 2015

Copy link to clipboard

Copied

Thank you both Ned and Dmennenoh!

I need to mantain my original script cause it is a little complex.

In my test if both two  text are set to MultiLine, if I compare the two text (and both text contain the same word)

with "=" it's ok if  use "==" the result is wrong;

If I set Single Line "=" and "==" are both good.

Thank you both!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 08, 2015 Mar 08, 2015

Copy link to clipboard

Copied

LATEST

Using "=" is not doing what you need if that is what you ended up doing...  "=" assigns the value of one to be equal to the other.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines