Skip to main content
Participant
March 13, 2013
Question

Trouble with array/loop/fade

  • March 13, 2013
  • 1 reply
  • 944 views

Hey guys/gals, I am new to actionscript and have used kglad's example to create images thet cycle through from an array. I have to figure out how to make them fade in and out between images and then loop continuously. I am taking an online class and have had some experience with actionscript (minimal to say the least) but I don't know where I need to put my fadeIn tween. Here is the code:

var count:int;

var imageArray:Array = new Array("image1.jpg", "image2.jpg", "image3.jpg", "image4.jpg", "image5.jpg", "image6.jpg", "image7.jpg", "image8.jpg", "image9.jpg", "image10.jpg", "image11.jpg", "image12.jpg", "image13.jpg", "image14.jpg", "image15.jpg", "image16.jpg");

var ldr0:Loader=new Loader();

ldr0.contentLoaderInfo.addEventListener(Event.COMPLETE,loadCompleteF);

var ldr1:Loader=new Loader();

ldr1.contentLoaderInfo.addEventListener(Event.COMPLETE,loadCompleteF);

play_btn.addEventListener(MouseEvent.CLICK,clickF);

function clickF(e:MouseEvent):void{

count=0;

loadF();

}

function loadF():void{

addChild(this["ldr"+count%2])

this["ldr"+count%2].load(new URLRequest(imageArray[count]));

       

    }

function loadCompleteF(e:Event):void{

// increment count

count++;

// check if the last has loaded

if(count<imageArray.length){

// if not clear the content out of the next loader.

if(this["ldr"+count%2].content){

this["ldr"+count%2].unloadAndStop();

}

// and call loadF so the next loader can load the next image in the array

loadF();

} else {

// if the last has loaded.

// last load completed

}

}

Any help would be appreciated.

Shannon

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
March 13, 2013

The fade in would have to occur after loading the image has completed.

Participant
March 13, 2013

So if I understand this correctly I would need to do this

function loadF():void{

addChild(this["ldr"+count%2])

this["ldr"+count%2].load(new URLRequest(imageArray[count]));

    }

fuction fadeIn(e:MouseEvent):void{

     var tweenFadeIn:Tween = new Tween(imageArray, "alpha", None.easeIn, 0, 1, 3, true);

}

Is that correct?

Ned Murphy
Legend
March 13, 2013

No.

You have a loadComplete function, so since you need to wait until the image is loaded, then somewhere in that function is where you need to put your fade in code.

The function you wrote appears to be driven by a MouseEvent, meaning something had to be interacted with via the mouse for the tween to occur.  But in your case, the tween should be occuring as a result of a loading event completing, not a mouse event

Your tween is trying to target the entire array as if it is a DisplayObject, while it is only an array of String values.  You really want to be targeting the loader.  If you wanted to tween the alpha property, then you should zero out the alpha property before the loading starts.

Before you starting tweening you probably want to place the loader on top (if they are sharing the same space, so you would need to use addChild() for it to have it assume the top position.