dtUser Posted October 20, 2010 Report Share Posted October 20, 2010 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. Quote Link to comment Share on other sites More sharing options...
falkencreative Posted October 20, 2010 Report Share Posted October 20, 2010 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... } } Quote Link to comment Share on other sites More sharing options...
dtUser Posted October 20, 2010 Author Report Share Posted October 20, 2010 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. Quote Link to comment Share on other sites More sharing options...
falkencreative Posted October 20, 2010 Report Share Posted October 20, 2010 Don't you need to place the if statement within the for loop? Quote Link to comment Share on other sites More sharing options...
dtUser Posted October 20, 2010 Author Report Share Posted October 20, 2010 falkencreative, that's it! Thank you so much for your help. It it now working. Quote Link to comment Share on other sites More sharing options...
falkencreative Posted October 20, 2010 Report Share Posted October 20, 2010 Awesome, glad to hear that fixed things for you. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.