7 Replies Latest reply on Mar 5, 2013 5:59 AM by Ned Murphy

    Array problem


      Stuck on something again for some time now!!


      "coordinatess" is an array containing numbers.

      I use "splice" to get items out of it randomly and store it in variable "s". My problem is that the items I get are not numbers, trace(typeof()) says they are objects, therefore cannot be used in setProperty to change coordinates of the movieclips. Have tried to convert them using Number() with no luck.


      for (j=0; j<nev.length; j++) {

                          r = random(coordinatess.length);

                          s = coordinatess.splice(r, 1);

                          setProperty("a"+j, _x, s);




      Thanks for looking!

        • 1. Re: Array problem
          Ned Murphy Adobe Community Professional & MVP

          While it depends on what you are tracing, the splice method returns an array, so you need to be tracing the elements of the returned array.


          How are you filling the coordinates array?  Coordinates are normally x/y pairs, which are more likely to be stored as an object if both are being stored together as a single entity.

          1 person found this helpful
          • 2. Re: Array problem
            mixedherbs Level 1

            Thanks Ned!


            I'm filling it like this:

            setProperty("a"+j, _x, s); //I'm not interested in the _y coordinates


            Have tried to fill it like this:

            coordinatess = [0, 140, 210, 280, 350];

            Same result, they are not numbers.


            Should I use something else instead of splice()  ?

            • 3. Re: Array problem
              Ned Murphy Adobe Community Professional & MVP

              It will probably help most if you can provide a fully coded example of something that is not working the way you want and explain what it is supposed to be doing.  The simpler you can keep it the better.

              • 4. Re: Array problem
                mixedherbs Level 1

                Oh ok, here it is:




                thename = "Johnny";

                coordinatess = [];

                var r;

                var s;

                for (i=0; i<thename.length; i++) {

                          this["letter"+i] = thename.charAt(i);                       //breaks up the name to variables

                          duplicateMovieClip(_root.klip_mc, "b"+i, i);                   //multiplies the movieclip

                          setProperty("b"+i, _x, i*70);                                   //spreads the clips out horizontally

                          _root["b"+i].thetext.text = this["letter"+i];               //displays a letter of the name in each movie clip

                          coordinatess.push(getProperty("a"+i, _x));                             //creates an array with the _x position of the movieclips


                b1.onRelease = function() {                                                                                          //to swap the movieclips position randomly on button press

                          for (j=0; j<thename.length; j++) {

                                    r = random(coordinatess.length);                                        //takes the lenght of the array

                                    s = coordinatess.splice(r, 1);                                                       //removes a random element and stores it in s

                                    setProperty("b"+j, _x, s);                                                                     //moves the clips to the coordinate that was taken from the array





                There is a name "Johnny" which gets broken up into individual letters and displayed in movieclips. I want to swap the movieclip's position randomly by first storing their _x position in an array, then removing them from the array in a random order and setting the property of the clips using a for loop.

                The problem is that the clips won't move, I "push" the coordinates into the array called "coordinatess" and remove them with "splice", but they are not numbers.

                • 5. Re: Array problem
                  Ned Murphy Adobe Community Professional & MVP

                  This is just a quick response based on your explanation and seeing


                  s = coordinatess.splice(r, 1);

                  setProperty("b"+j, _x, s);


                  As I mentioned earlier, the splice method returns an array, so "s" is an array.  As long as you only placed one value in that array, the correct way to access the value in that array is to use...  s[0]


                  setProperty("b"+j, _x, s[0]);

                  • 6. Re: Array problem
                    mixedherbs Level 1

                    Thank you Ned, yes, this is what you and Flash has been trying to tell me. :-) It's working now.


                    • 7. Re: Array problem
                      Ned Murphy Adobe Community Professional & MVP

                      You're welcome David