Skip navigation
legoheaddp
Currently Being Moderated

ActionScript 3 help, shuffling arrays: shuffling 3 cups.

Apr 10, 2012 10:49 AM

Tags: #as3 #3.0 #array #actionscript #flash_cs5 #tween #shuffling

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{

shuffle(posArray);

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!

 
Replies
  • Currently Being Moderated
    Apr 10, 2012 12:20 PM   in reply to legoheaddp

    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.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points