Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
The fade in would have to occur after loading the image has completed.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Ok thanks for the help Ned but I have tried to figure out where it would go. I found a simple actionscript tutorial on changing images using a timer. It works great but I cannot figure out how to add a fade effect (each picture fades in as the other fades out) into the UILoader. Here is the code.
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 currentImage:uint = 0;
var lastImage:uint = 15;
var imageTimer:Timer = new Timer(4000);
imageTimer.addEventListener(TimerEvent.TIMER, changeImage);
function changeImage(e:TimerEvent){
loadWindow.source = imageArray[currentImage];
currentImage++;
if(currentImage > lastImage){
currentImage = 0;
}
}
imageTimer.start();
Once again any help would be appreciated.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now