Killersites Community: Input text field used to search content - Killersites Community

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Input text field used to search content using an Array in an input text field

#1 User is offline   dtUser 

  • View blog
  • Group: New Members
  • Posts: 4
  • Joined: 20-October 10

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 User is offline   Ben 

  • View blog
  • Group: Administrators
  • Posts: 5,409
  • Joined: 19-December 08
  • 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...
    }
}

Benjamin Falk | Falken Creative : Twitter : KillerSites Screencast Blog
Skills: Photoshop, Illustrator, HTML, CSS, jQuery, PHP and CodeIgniter
0

#3 User is offline   dtUser 

  • View blog
  • Group: New Members
  • Posts: 4
  • Joined: 20-October 10

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 User is offline   Ben 

  • View blog
  • Group: Administrators
  • Posts: 5,409
  • Joined: 19-December 08
  • LocationChico, CA

Posted 20 October 2010 - 03:41 PM

Don't you need to place the if statement within the for loop?
Benjamin Falk | Falken Creative : Twitter : KillerSites Screencast Blog
Skills: Photoshop, Illustrator, HTML, CSS, jQuery, PHP and CodeIgniter
0

#5 User is offline   dtUser 

  • View blog
  • Group: New Members
  • Posts: 4
  • Joined: 20-October 10

Posted 20 October 2010 - 06:00 PM

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

#6 User is offline   Ben 

  • View blog
  • Group: Administrators
  • Posts: 5,409
  • Joined: 19-December 08
  • LocationChico, CA

Posted 20 October 2010 - 06:35 PM

Awesome, glad to hear that fixed things for you.
Benjamin Falk | Falken Creative : Twitter : KillerSites Screencast Blog
Skills: Photoshop, Illustrator, HTML, CSS, jQuery, PHP and CodeIgniter
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users