-
Background external images fadeIn and fadeOut
Hello,
I have a background with several external images that I want to fadeIn and fadeOut but so far I managed to swich images only randomly without fade. Can anyone help me to modify my code?
Code:
myImageArray = ["alfaBG1.jpg", "alfaBG2.jpg", "alfaBG3.jpg"];
_global.changeImage = function() {
myImage = myImageArray[random(myImageArray.length)];
photo.loadMovie("Background/" + myImage);
clearInterval(_root.changeImageIval);
_root.changeImageIval = setInterval(changeImage, ((random(10)+1) * 2000) );
}
-
.
Hi,
You will be better off using MovieClipLoader(), as you will have control over the loading and unloading the images, like so
PHP Code:
import mx.transitions.Tween; import mx.transitions.easing.*;
var target:MovieClip;
var myImageArray:Array = ["alfaBG1.jpg", "alfaBG2.jpg", "alfaBG3.jpg"];
var imageLoader = new MovieClipLoader(); var imageListener = new Object(); imageLoader.addListener(imageListener); imageLoader.loadClip("Background/" + myImageArray[0],photo);
imageListener.onLoadStart = function(target) { trace("Loading image"); }; imageListener.onLoadProgress = function(target, loadedBytes, totalBytes) { percent = Math.floor((loadedBytes / totalBytes) * 100); trace(percent); }; imageListener.onLoadComplete = function(target) { trace("Image loaded"); }; imageListener.onLoadInit = function(target) { new Tween(target, "_alpha", None.easeNone, 0, 100, 1, true); };
function getImage() { myImage = myImageArray[random(myImageArray.length)]; trace(myImage); imageLoader.loadClip("Background/" + myImage,photo); }
imageInterval = setInterval(getImage, 5000);
you might need to get a grip of your use of _root everywhere, as it will become confusing, if you can keep all code together on the main timeline it will be far easier to target everything,
good luck
-
Thank you fruitbeard, I'll give it a try
-
It's like bad habit, I need to put root everywhere
Angel sugsested to use loadMovie, at this point I can't realy make any difference between loadMovie and MovieClipLoader, they both load images externally. I might need to look some tuts about that.
-
.
Hi,
I don't see any Angel in this thread, I think you will find MovieClipLoader is better though, but if you wish to use loadMovie then do so.
You might also want to think about putting your images into an xml file too, so you can add and take away at will without having to open the fla
-
Oh I ment AngelHdz, he helped me a while ago and then he told me to use loadMovie. Anyway your code works perfectly.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|