Jump to content
Search Community

ShuffleArray question.

UbiAssassin test
Moderator Tag

Recommended Posts

Hello everyone,

 

I am sorry that this is offtopic and not specific to Greensock, but I get a lot of great help and responses here, so I thought I would try :)

 

My problem is that I shuffle my array of 16 images and then pick from that array to place an image on a thumbplate. It works perfectly most of the time. Sometimes, however, one of the already loaded images gets removed from the array and therefore removed from its image plate during another shuffle pass. I am loading images on to 6 plates, so the shuffle runs 6 times. Here is my shuffle code:

 

public function shuffleArray(input:Array):void
{
for (var i:int = input.length - 1; i > 0; i--)
{
var randomIndex:int = Math.floor(Math.random() * (i + 1));
var itemAtIndex:Object = input[randomIndex];
input[randomIndex] = input[i];
input[i] = itemAtIndex;
}
}

 

Does anyone see a way that I can avoid already placed images from getting removed?

 

Here is the PickFromArray code I am using, in case the issue is in there:

 

public function pickFromScreenArray():void
{
trace("Grab a New Image");
var imageArray:Array = ["AssassImageSA", "AssassImageSB", "AssassImageSC", "AssassImageSD", "AssassImageSE", "AssassImageSF", "AssassImageSG", "AssassImageSH", "AssassImageSI", "AssassImageSJ", "AssassImageSK", "AssassImageSL", "AssassImageSM", "AssassImageSN", "AssassImageSO", "AssassImageSP", "AssassImageSQ"];
shuffleArray(imageArray);
addChildAt(LoaderMax.getContent(imageArray[0]), 1);
var currentImage:DisplayObject = getChildAt(1);
currentImage.alpha = 0;
TweenMax.fromTo(currentImage, 2, {autoAlpha: 0}, {autoAlpha: 1, ease: Quad.easeIn});
}

 

Thanks for looking :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...