A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: <b>This slideshow code is killing me!</b>

  1. #1

    <b>This slideshow code is killing me!</b>

    I know it's not in good forum taste to repeat a post, but this slideshow code may very well cause my girlfriend to leave me if I can't find a way to to make it work and pay some attention to her.

    I know someone out there in FlashKit world has to be able to point me in the right direction. Upon recommendation, from jbum, I bought "O'Reilly's, ActionScript for Flash MX, The Definitive Guide". This book is great, but very thick and will take me awhile to complete, so in the mean time, I hope one of you hardcore ActionScripters could help me out.

    THE PROBLEM:

    Basicly, I am trying to implement jbum's slideshow code (listed below) into my flash movie by putting it in a movieClip instead of on the main (_root) timeline, with no luck. The code works perfectly if I put it directly on the Main.swf timeline (_root) but when I try to run it from a movieClips timeline which is placed on the _root timeline it does not work. I gathered from aaaaloooot of reading that by running inside a MovieClip the paths get messed up. The problem is I'm not sure which lines of code to change to get it to work right.

    :::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::
    This is the general idea:

    I have my MAIN.swf movie.
    Then inside of that I have a movieClip called "holder_mc"
    I place the slideshow code in frame 1 of "holder_mc" and place it on the MAIN.swf's _root timeline.
    .....and nothing. doesn't work.
    :::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::

    I've changed all of the paths in the code to reflect the location of the code
    but I'm not doing something right, obviously.

    So once again, here is jbum's slideshow code I'm trying to impliment:

    Code:
    // Basic Slide Show with Fades - Jim Bumgardner
    //
    
    // number of seconds to display pictures between fades
    kDispSeconds  = 5;
    
    // duration of fade in/out effect, in seconds
    // note that total out+in will be twice this amount (since there are two effects)
    kFadeDuration = 1;
    
    // path to your pictures, ending with slash
    // or nothing at all, if pictures are in same directory
    picPath = "";
    
    // names of your pictures			   
    pics = ["dobbs_blind.jpg", "eggplant.jpg", "fez.jpg"];
    
    _root.createEmptyMovieClip("myMovieClip", 1);
    myMovieClip.createEmptyMovieClip("imageHolder", 1);
    myMovieClip.picNumber = -1;
    myMovieClip._alpha = 0;
    
    // Note: position myMovieClip here....
    myMovieClip._x = 10;
    myMovieClip._y = 10;
    
    // This performs both our fade ins and outs.  It does easing on both effects
    // When the fade is finished, a completion function is called.
    MovieClip.prototype.fadeIterate = function()
    {
    	var elapsed = getTimer() - this.startFade;  // get elapsed time
    	var r = elapsed / this.fadeDuration;        // convert to a ratio (0 - 1)
    	if (r >= 1.0) {  // finished?
    		this._alpha = this.tAlpha; // set our final alpha value
    		this.onEnterFrame = undefined; // stop calling this function
    		this.completionFunc();  // and call the completion function (once)
    	}
    	else {
    		r = r*r*(3-2*r); // ease in/out
    		this._alpha = this.sAlpha + this.dAlpha*r; // perform the fade on alpha
    	}
    }
    
    // This sets up our fade
    // We tell it what alpha value to fade to, how long to take, and what
    // completion function to call
    MovieClip.prototype.setupFade = function(tAlpha, fadeDuration, completionFunc)
    {
        this.startFade = getTimer(); // current clock
    	this.tAlpha = tAlpha;       // end of fade alpha value
    	this.sAlpha = this._alpha;  // start of fade alpha value
    	this.dAlpha = this.tAlpha - this.sAlpha;  // range of alpha values to tween
    	this.fadeDuration = fadeDuration*1000; // duration of fade in milliseconds
    	this.completionFunc = completionFunc;  // what to do when fade is finished
    	this.onEnterFrame = this.fadeIterate;  // let'er rip!
    }
    
    // This gets called when we're done viewing an image
    MovieClip.prototype.doneViewing = function()
    {
    	clearInterval(this.viewH);
    	this.setupFade(0, kFadeDuration, this.loadNextPic);
    }
    
    // This gets called repeatededly when we're loading an image
    MovieClip.prototype.checkLoaded = function()
    {
    	this._alpha = 0;
    	// are we loaded yet?
    	if (this.imageHolder.getBytesLoaded >= this.imageHolder.getBytesTotal())
    	{   // yep
    		this.onEnterFrame = undefined; // stop calling this function
    		// and start fading in.  When fade in is complete, set up a fade out for when we're done viewing
    		this.setupFade(100, kFadeDuration, function() { this.viewH = setInterval(this, "doneViewing", kDispSeconds*1000); } );
    	}
    }
    
    // Load the next image in the array
    MovieClip.prototype.loadNextPic = function()
    {
        // this gets the next image number, looping around at the end
    	this.picNumber = (this.picNumber + 1) % _root.pics.length;
    	// load in the image
    	this.imageHolder.loadMovie(picPath + _root.pics[this.picNumber]);
    	// and start checking to see if it's done loading
    	this.onEnterFrame = checkLoaded;
    }
    
    // Let'er rip...
    myMovieClip.loadNextPic();

    Once again, I apoligize for repeating my post and problem, but it's really for my possible future wife's benefit.

    Thanks again.

  2. #2
    Senior Member stoc's Avatar
    Join Date
    Nov 2001
    Location
    Romania, Arad
    Posts
    428
    Here is th code I changed - and it is works ok if you put it in any movieclip

    What I did :

    I added a global variable in which I stored reference to current movieclip :
    _global.mc_root = this
    and I simply replaced in code - all the _root. with _global.mc_root..

    I hope I saved your relation ...

    code:

    // Basic Slide Show with Fades - Jim Bumgardner
    //

    // setting reference to current movieclip as it was used in root
    _global.mc_root = this

    // number of seconds to display pictures between fades
    kDispSeconds = 5;

    // duration of fade in/out effect, in seconds
    // note that total out+in will be twice this amount (since there are two effects)
    kFadeDuration = 1;

    // path to your pictures, ending with slash
    // or nothing at all, if pictures are in same directory
    picPath = "";

    // names of your pictures
    pics = ["1.jpg", "2.jpg", "3.jpg"];

    _global.mc_root.createEmptyMovieClip("myMovieClip" , 1);
    myMovieClip.createEmptyMovieClip("imageHolder", 1);
    myMovieClip.picNumber = -1;
    myMovieClip._alpha = 0;

    // Note: position myMovieClip here....
    myMovieClip._x = 10;
    myMovieClip._y = 10;

    // This performs both our fade ins and outs. It does easing on both effects
    // When the fade is finished, a completion function is called.
    MovieClip.prototype.fadeIterate = function()
    {
    var elapsed = getTimer() - this.startFade; // get elapsed time
    var r = elapsed / this.fadeDuration; // convert to a ratio (0 - 1)
    if (r >= 1.0) { // finished?
    this._alpha = this.tAlpha; // set our final alpha value
    this.onEnterFrame = undefined; // stop calling this function
    this.completionFunc(); // and call the completion function (once)
    }
    else {
    r = r*r*(3-2*r); // ease in/out
    this._alpha = this.sAlpha + this.dAlpha*r; // perform the fade on alpha
    }
    }

    // This sets up our fade
    // We tell it what alpha value to fade to, how long to take, and what
    // completion function to call
    MovieClip.prototype.setupFade = function(tAlpha, fadeDuration, completionFunc)
    {
    this.startFade = getTimer(); // current clock
    this.tAlpha = tAlpha; // end of fade alpha value
    this.sAlpha = this._alpha; // start of fade alpha value
    this.dAlpha = this.tAlpha - this.sAlpha; // range of alpha values to tween
    this.fadeDuration = fadeDuration*1000; // duration of fade in milliseconds
    this.completionFunc = completionFunc; // what to do when fade is finished
    this.onEnterFrame = this.fadeIterate; // let'er rip!
    }

    // This gets called when we're done viewing an image
    MovieClip.prototype.doneViewing = function()
    {
    clearInterval(this.viewH);
    this.setupFade(0, kFadeDuration, this.loadNextPic);
    }

    // This gets called repeatededly when we're loading an image
    MovieClip.prototype.checkLoaded = function()
    {
    this._alpha = 0;
    // are we loaded yet?
    if (this.imageHolder.getBytesLoaded >= this.imageHolder.getBytesTotal())
    { // yep
    this.onEnterFrame = undefined; // stop calling this function
    // and start fading in. When fade in is complete, set up a fade out for when we're done viewing
    this.setupFade(100, kFadeDuration, function() { this.viewH = setInterval(this, "doneViewing", kDispSeconds*1000); } );
    }
    }

    // Load the next image in the array
    MovieClip.prototype.loadNextPic = function()
    {
    // this gets the next image number, looping around at the end
    this.picNumber = (this.picNumber + 1) % _global.mc_root.pics.length;
    // load in the image
    this.imageHolder.loadMovie(picPath + _global.mc_root.pics[this.picNumber]);
    // and start checking to see if it's done loading
    this.onEnterFrame = checkLoaded;
    }

    // Let'er rip...
    myMovieClip.loadNextPic();

    Stoc Digital Studio - Web Applications Development
    http://www.stoc-studio.ro

  3. #3
    Great, that works! and yes, you may have saved me from having a loveless exsistance.

    Thank you, I really appreciate you taking the time, that was driving me nuts for 3 or 4 days.

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