Hello everyone,
I have a class associated to my movie, and a second class that defines my thumbnail. The thumbnail definition class (ScreenButtonScript) places the background image at child level 0, places a random image from my array at child level 1, and finally places the invisible hitplates that detect mouse movements at child level 3. Every time a new instance of (ScreenButtonScript) is called from my main class it places a new thumbplate with a new image and one of the already loaded and placed thumbplates will lose its image picked from the array. I am always placing 6 instances of the thumbplate on the stage through the main class, and I always lose one of the images at child Level 1 of one of the thumbplates.
In the ScreenButtonScript, I shuffle my array of 16 images and then pick from that array to place an image on the thumbplate instance. It works perfectly most of the time. Sometimes, however, one of the already loaded images gets removed from the array? Therefore it is 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*;
input* = 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