4 Replies Latest reply on Aug 25, 2006 2:26 PM by blemmo

    prototype function problem

    sbryner Level 1
      Help, I'm stuck. I've got a prototype that works. I can pull out one of the new array entries from it.

      I want to be able to pull out all the array elements and place their properites (if more than one element is in the array) and put their respective pictures and names in another location.

      the link below may help you understand what I'm trying to accomplish.

      --Sky's Flash Test --- Click here to view

      please help, I've looked all over and found nothing that is working for me.
        • 1. Re: prototype function problem
          blemmo Level 1
          You're calling the goodsearch function inside the id function, which does the actual search, that's the wrong way around. The id function is supposed to search the array and then return the found items, so you can just use the result of this inside the goodsearch function. Try the attached code. The search function might also get the parameters (key and value) and just pass it along to the id function inside.
          To display the results, you can fill in the text in the main area with a fixed index, and add the other results in a loop through the result array, or also with a defined index. Depends on what results shall be displayed.


          • 2. Re: prototype function problem
            Level 7
            You're calling the goodsearch function inside the id function, which does the
            actual search, that's the wrong way around. The id function is supposed to
            search the array and then return the found items, so you can just use the
            result of this inside the goodsearch function. Try the attached code. The
            search function might also get the parameters (key and value) and just pass it
            along to the id function inside.
            To display the results, you can fill in the text in the main area with a fixed
            index, and add the other results in a loop through the result array, or also
            with a defined index. Depends on what results shall be displayed.




            myArray = [{myname:"bob", town:"London", id:1, pic:"1.gif"},
            {myname:"hans", town:"Munich", id:2, pic:"2.gif"},
            {myname:"manuel", town:"Barcelona", id:3, pic:"3.gif"},
            {myname:"bob", town:"Newark", id:4, pic:""}];

            Array.prototype.id = function(prop, val) {
            var res:Array = new Array();
            var i = this.length;
            while (i--) {
            if (this [prop] == val) {
            res.push(this
            );
            } else {
            trace("I'm in else");
            }
            }
            return (res);
            };

            getInfo_mc.onRelease = function() {
            var getConvertText = it_txt.text;
            var convertedToLowerCase = getConvertText.toLowerCase();
            var getName = convertedToLowerCase;
            goodsearch();
            };

            function goodsearch() {
            //trace("this is a good search");
            // call the search
            var searchResult:Array = myArray.id("myname","bob");
            // set the text 1 (static index)
            dtName_txt.text = searchResult[0].myname;
            dtTown_txt.text = searchResult[0].town;
            dtAddress_txt.text = searchResult[0].id;
            imageLoader.contentPath = searchResult[0].pic;
            // text 2, static index or loop here
            dtAnother_txt.text = "Another "+searchResult[0].myname+" lives in ";
            dtSecName_txt.text = searchResult[1].town;
            imageLoader2.contentPath = searchResult[1].pic;
            }

            • 3. Re: prototype function problem
              sbryner Level 1
              Thanks, Blemmo!

              Works Awesome! Now for the Next Step

              Thanks again for all the help.
              • 4. Re: prototype function problem
                blemmo Level 1
                you're welcome.

                cheers,
                blemmo