1 Reply Latest reply on Oct 3, 2009 7:06 AM by Ned Murphy

    Random MovieClip script not selecting from all possible outcomes

    mintdoctor

       

      i have a collection of movie clips (mc0, mc1, mc2...etc etc),
      and when motion is detected on a webcam, one of these clips is shown on the stage.

      however, for some reason only mc0, mc1 and mc2 are being displayed,
      and i cannot get mc3, mc4 or any more to be chosen.

      Code:
      import flash.filters.*

      // Assumes a Video object named "myVideoObject" is on the Stage
      active_cam = Camera.get();

      filterList = [
                       /* 0 */ "multiply",
                       /* 1 */ "multiply",
                       /* 2 */ "multiply",
                      /* 3 */ "multiply",
                      /* 4 */ "multiply"
                       ];

      positionList = [
                       /* 0 */ {_x: 512, _y: 288},
                       /* 1 */ {_x: 512, _y: 288},
                       /* 2 */ {_x: 512, _y: 288},
                      /* 3 */ {_x: 512, _y: 288},
                       /* 4 */ {_x: 512, _y: 288}

                       ];



      myVideoObject.attachVideo(active_cam);
      active_cam.setMotionLevel(95, 100);
      active_cam.onActivity = function(mode)
      {
          trace(mode);
           var randId = Math.floor(Math.random() *
      5);

           var init = positionList[randId];
           /* old init... {_x: Math.random() * _root._width, _y:Math.random() * _root._height}; */
           var depth = _root.getNextHighestDepth();
           var movieId = "mc" + randId;
           if(mode) {
                var mc = _root.attachMovie(movieId, movieId + depth, depth, init);
                mc.blendMode = _root.filterList[randId];
           }
      }
      I had the first three working fine, so when i added 2 more to the Filter and position Lists, and changed
      the Mathrandom mutliplier to 5 instead of 3, i thought that would work.

      Im really stumped, id like the script to choose from many more than 3 movie clips
        • 1. Re: Random MovieClip script not selecting from all possible outcomes
          Ned Murphy Adobe Community Professional & MVP

          You should put a trace to check the movieId value to confirm that the code calls for movies > 2.

           

          The random selection code should be fine as is, so you may have to wait a bit to see one of the movies you say is not displaying.  If you were to increase the number of them, the chances of seeing some in the range > 2 is better.  The only thing I can think of from your code that might prohibit showing something > 2 is the mode value, since that's the only thing that prohibits display of anything.

           

          I am not at all familiar with video cams andactionscript regarding them, but would it be necessary to clear out the current mc# from being present/active before adding a new one?

          1 person found this helpful