A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: How to display multiple search results one at a time

  1. #1
    Member
    Join Date
    Aug 2009
    Posts
    44

    How to display multiple search results one at a time

    I am trying to adapt this search code to display the results one at a time.Right now it displays all the terms it finds all at once and separated by commas. How would I adapt the code so it displays one item or term at a time.

    Code:
    //we count all matches
    matchesArray.push(myItem01);
    
    //length determines number of matches
    var mLength:Number = matchesArray.length;
    _root.textField1.text = mLength+"<FONT COLOR=\"#000000\"> matches found !</FONT>";
    _root.textField2.text = "";
    iDescription.push(itemDescription);
    
    /*
    var my_strtring = new String( iDescription );
    var i:Number = my_str.length;
    trace(my_str.slice( 1, i ));
    */
    
    _root.mainField.text = iDescription;
    }/
    Any ideas would be appreciated.

  2. #2
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    guessing iDescription is the csv array, you could use a variable to increment by 1 and iterate through each item, as in iDescription[0] then iDescription[1] etc. until iDescription[length]

    gparis

  3. #3
    Member
    Join Date
    Aug 2009
    Posts
    44
    Thanks for the suggestion gparis. As I am almost illiterate in actionscript, I need help with coding. I tried before using something like this:

    Code:
    var i = mlength ;
    for(var i=0;i!=mlength;i++){
    _root.mainField.text = iDescription[i];
    and considered adding another a textfield to announce "no more matches left!". However, that didn't work and I get "unidentified" displayed as the mainField.text. I know I must be doing something wrong but I am not good enough to discover what it is. Again any help would be appreciated.

  4. #4
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    no that doesn't mean anything.

    What if you write that:
    _root.mainField.text = iDescription[0];
    instead of:
    _root.mainField.text = iDescription;

    Do you get the first result?

    or, if you don't, try this:
    _root.mainField.text = matchesArray[0];


    gparis

  5. #5
    Member
    Join Date
    Aug 2009
    Posts
    44
    Hey gparis, thank a bunch,

    _root.mainField.text = iDescription[0];

    did the trick and I get the trick and I get the first result!
    How do I go through the rest of the resuls?

  6. #6
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    as i said in the first post: replace 0 by a var you increment until the end of the array by button or interval action.

    gparis

  7. #7
    Member
    Join Date
    Aug 2009
    Posts
    44
    I tried to do like this:

    Code:
    for (i= 0; i>wordArray.length; i++) {
    _root.mainField.text = iDescription[i];
    }
    triggered by a button, but it didn't work. What's wrong with this?

  8. #8
    Member
    Join Date
    Aug 2009
    Posts
    44
    Correction: that's matchesArray.length instead of wordArray.length...
    Still doesn't work though.

  9. #9
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    no you didn't undestand. What you ask for is this:
    iDescription[0];
    then
    iDescription[1];
    then
    iDescription[2];
    then
    iDescription[3];
    etc..

    How you want to call them is your choice (as i said, by button action or by interval), but using a for loop won't work if you need to display them one at a time. That is what you had before and apparently do not want anymore:
    How would I adapt the code so it displays one item or term at a time
    One at a time = no for loop. Read back my posts, i'm repeating myself now.

    gparis

  10. #10
    Member
    Join Date
    Aug 2009
    Posts
    44
    sorry for my ignorance in actionscript...seems like I don't know my if's from my loops!! I just want you to know that I have tried many things for the past two days with no luck. I tried code for "next" buttons like:

    Code:
    i == matchesArray.length-1 ? i = matchesArray.length-1 : i++;
    and also if statements like:
    Code:
       if (i < matchesArray.length) {
           i ++;
    						 }
       }else{
         i = 0;
       }
    among many other attempts. Are these at least steps in the right direction? Would I be able to incorporate the correct code under the same "search" button that starts the function and returns the first result or do I have to insert another button (that will be the easiest route for me?
    I know that it must be difficult dealing with newbies like me, but if you can find the patience to stick it out with me, it is very much appretiated. But if you cannot, I still thank you for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center