Jump to content

Input text field used to search content


dtUser

Recommended Posts

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.

Link to comment
Share on other sites

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...
   }
}

Link to comment
Share on other sites

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);

 

}

 

if (inputText == aDsx){

Run this function ();

}

The trace statement works but the input text field does not.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...