Jump to content


Photo

Input text field used to search content


  • Please log in to reply
5 replies to this topic

#1 dtUser

dtUser

    New member

  • New Members
  • 4 posts

Posted 20 October 2010 - 10:18 AM

Flash ActionScript 2.0 question about Arrays and input text fields.

I’m using an input text field (instance name: inputText)for a Search in a Flash virtual tour.

The user types in a keyword and clicks on a Search button. In the Search button, I have an ‘if’ statement that reads:

If (inputText == “thekeywordtext”){
Run this function ();
}
So, for example if I want the user to run a particular function if they type in ‘dsx1’, I’m thinking they could also type in dsx-1, dsx, digital cross connect, x-connect etc.

Can I use an array with these variations for searching and then in my if statement reference the array?

So:
var myArray:Array = new Array();
myArray[0] = "dsx";
myArray[1] = "dsx1";
myArray[2] = "dsx-1";
myArray[3] = "digital signal cross-connect";


If (inputText == myArray){
Run this function();
}
Thanks.
  • 0

#2 Ben

Ben

    Administrator

  • Administrators
  • 5,643 posts
  • LocationChico, CA

Posted 20 October 2010 - 10:43 AM

I know very little about Actionscript, so I'm not sure how I can help you in this case.

However, common programming practices tell me that the method you describe above ("inputText == myArray") won't work. You'll need to create a loop and loop through each of the array's values, comparing them each time.

In PHP, you'd do something like this (and it should be similar in Actionscript. The same principles should apply.)

for ($i = 0; $i < count(myArray)-1; $i++)
{
    if (inputText == myArray[i])
    {
        ...run function...
    }
}

  • 0
Benjamin Falk
Falken Creative : Twitter

#3 dtUser

dtUser

    New member

  • New Members
  • 4 posts

Posted 20 October 2010 - 01:35 PM

I've tried using a for loop with my array and also changed the 'if' statement.
var aDsx:Array = new Array();
aDsx[0] = "dsx";
aDsx[1] = "dsx-1";
aDsx[2] = "dsx1";
aDsx[3] = "dsx3";
aDsx[4] = "dsx-3";
aDsx[5] = "digital signal cross-connect";

for (var i =0; i<aDsx.length; i++){
//trace (aDsx[i]);

}

if (inputText == aDsx[i]){
Run this function ();
}
The trace statement works but the input text field does not.
  • 0

#4 Ben

Ben

    Administrator

  • Administrators
  • 5,643 posts
  • LocationChico, CA

Posted 20 October 2010 - 03:41 PM

Don't you need to place the if statement within the for loop?
  • 0
Benjamin Falk
Falken Creative : Twitter

#5 dtUser

dtUser

    New member

  • New Members
  • 4 posts

Posted 20 October 2010 - 06:00 PM

falkencreative, that's it! Thank you so much for your help. It it now working.
  • 0

#6 Ben

Ben

    Administrator

  • Administrators
  • 5,643 posts
  • LocationChico, CA

Posted 20 October 2010 - 06:35 PM

Awesome, glad to hear that fixed things for you.
  • 0
Benjamin Falk
Falken Creative : Twitter




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users