A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Background external images fadeIn and fadeOut

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    21

    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) );
    }

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    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(targetloadedBytestotalBytes)
    {
        
    percent Math.floor((loadedBytes totalBytes) * 100);
        
    trace(percent);
    };
    imageListener.onLoadComplete = function(target)
    {
        
    trace("Image loaded");
    };
    imageListener.onLoadInit = function(target)
    {
        new 
    Tween(target"_alpha"None.easeNone01001true);
    };

    function 
    getImage()
    {
        
    myImage myImageArray[random(myImageArray.length)];
        
    trace(myImage);
        
    imageLoader.loadClip("Background/" myImage,photo);
    }

    imageInterval setInterval(getImage5000); 
    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

  3. #3
    Junior Member
    Join Date
    Jan 2014
    Posts
    21
    Thank you fruitbeard, I'll give it a try

  4. #4
    Junior Member
    Join Date
    Jan 2014
    Posts
    21
    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.

  5. #5
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    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

  6. #6
    Junior Member
    Join Date
    Jan 2014
    Posts
    21
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center