1 Reply Latest reply: Apr 10, 2012 12:20 PM by Ned Murphy RSS

    ActionScript 3 help, shuffling arrays: shuffling 3 cups.

    legoheaddp Community Member

      Hi, I'm having a problem with this file. It's meant to shuffle 3 cups but I get this error: TypeError: Error #1010: A term is undefined and has no properties.

      at cupsc_fla::MainTimeline/frame1().

      It was working in AS2 but I changed it around to get it to work for AS3 but now it won't work.


      Here's the code:


      import fl.transitions.Tween;

      import fl.transitions.easing.*;

      import flash.events.*;


      var posArray:Array = new Array(cup0.DisplayObject.x, cup1.DisplayObject.x, cup2.DisplayObject.x);


      move_mc.addEventListener(MouseEvent.CLICK, pressBtn);



      shuffle = function (targetArray) {

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

      var tmp = targetArray[i];

      var randomNum = Math.random(targetArray.length);

      targetArray[i] = targetArray[randomNum];

      targetArray[randomNum] = tmp;




      function pressBtn(e:Event) :void{


      var tween0 = new Tween(cup0, "_x", Strong.easeIn, cup0.DisplayObject.x, posArray[0], 1.5, true);

      var tween1 = new Tween(cup1, "x", Strong.easeIn, cup1.DisplayObject.x, posArray[1], 1.5, true);

      var tween2 = new Tween(cup2, "x", Strong.easeIn, cup2.DisplayObject.x, posArray[2], 1.5, true);



      I'm stumped!

        • 1. Re: ActionScript 3 help, shuffling arrays: shuffling 3 cups.
          Ned Murphy ACP/MVP

          There are a number of potential issues with the code as you show it. 


          cup0.DisplayObject.x,  ??? what are these


          shuffle = function... change that to be written just like your pressBtn function


          Math.random(nothing goes in here)... should be Math.random()*targetArray.length, although you want to get an integer value out of it, not a decimal value


          As far as the 1010 error goes, go into your Flash Publish Settings and select the option to Permit Debugging.  That can help by adding the line number of the offending code to the error message.