Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 07-13-2004, 11:09 PM   #1
tweaknee
Design to the Rescue
 
Join Date: May 2004
Location: Seattle WA
Posts: 83
Question pleeeze help noobee: yet another centered loaded jpg image question

I'm using this wonderful slide show code found somewhere on here, that fades images in and out very nicely. I have an empty movie clip called photo on the main stage, and a folder of jpgs both landscape and portrait. So far so good.
Code:
 fscommand("allowscale", "false"); 
this.pathToPics = "images/"; 
// fill this array with your pics 
this.pArray = ["image1.jpg",  "image2.jpg", "image3.jpg", "image4.jpg", "image5.jpg"]; 
this.fadeSpeed = 15; 
//Was 20... 
this.pIndex = 0; 
// MovieClip methods ---------------------------------- 
// d=direction; should 1 or -1 but can be any number 
//loads an image automatically when you run animation 
_level0.autoPlay = true; 
_level0.autoPlay = true; 
trace("AUTOPLAY IS ON!"); 
setTimerCtrl(); 
// Picture will change in 5 seconds, as set in the setTimerCtrl() function. 

loadMovie(this.pathToPics + this.pArray[0], _root.photo); 

changePhoto = function(d) 
{ 
    // make sure pIndex falls within pArray.length 
     //    this.pIndex = (this.pIndex+d)%this.pArray.length; 
     //    if (this.pIndex<0) { 
     if ((this.pIndex + d) < (this.pArray.length - 1)) 
    { 
        this.pIndex++; 
    } 
    else 
    { 
        this.pIndex = this.pArray.length - 1; 
        //MY ADDITION TO THE CODE TO END THE SLIDE SHOW AFTER THE LAST JPG 
        trace("AUTOPLAY IS OFF!"); 
        _level0.autoPlay = false; 
        clearInterval(intervalID); 
        //Clear the interval created from the auto state. 
     } 
    trace("\tthis.pIndex = " + this.pIndex); 
    this.onEnterFrame = fadeOut; 
}; 
fadeOut = function() 
{ 
    if (this.photo._alpha > this.fadeSpeed) 
    { 
        this.photo._alpha -= this.fadeSpeed; 
    } 
    else 
    { 
        this.loadPhoto(); 
    } 
}; 
loadPhoto = function() 
{ 
    // specify the movieclip to load images into 
    var p = _root.photo; 
    //------------------------------------------ 
    p._alpha = 0; 
    trace("this.pIndex = " + this.pIndex); 
    trace("this.pArray = " + this.pArray); 
    trace("this.pArray[this.pIndex] = " + this.pArray[this.pIndex]); 
    trace("this.pathToPics+this.pArray[this.pIndex] = " + (this.pathToPics + this.pArray[this.pIndex])); 
    p.loadMovie(this.pathToPics + this.pArray[this.pIndex]); 
    this.onEnterFrame = loadMeter; 
}; 
loadMeter = function() 
{ 
    var i, l, t; 
    l = this.photo.getBytesLoaded(); 
    t = this.photo.getBytesTotal(); 
    if (t > 4 && t == l) 
    { 
        this.onEnterFrame = fadeIn; 
		
     
    } 
    else 
    { 
        trace(l / t); 
    } 
}; 
fadeIn = function() 
{ 
    if (this.photo._alpha < 100 - this.fadeSpeed) 
    { 
        this.photo._alpha += this.fadeSpeed; 
    } 
    else 
    { 
        this.photo._alpha = 100; 
        this.onEnterFrame = null; 
    } 
}; 
// Actions that should advance the slide show one image.  See script on button for more script. 
/* MY ADDITION AND CHANGE */ 
function setTimerCtrl() 
{ 
    autoTimer = 5000; 
    //5 seconds between pictures... Number of seconds * 1000... 
    clearInterval(intervalID); 
    //Clear the interval for auto slide 
    intervalID = setInterval(autoSlide, autoTimer); 
    //Set an interval for auto slide 
} 
function autoSlide() 
{ 
    _root.changePhoto(1);
    
}
I've searched and tried for two days to figure out what to modify to have the images appear centered, as they are both portrait and landscape jpgs. If I add centering code to the "photo" movieclip itself with an onClipEvent, it's ignored. If I add it to the code above it either crops the image or ignores it.

I understand the concept of the image needing to load before the height and width is available, and assigning the value of half the height and half the width to the x and y position of the clip. I'm just not sure where to add this kind of code to make it work with the auto-loading slide show.

Any help/hints are hugely appreciated.
tweaknee is offline   Reply With Quote
Old 07-15-2004, 12:27 AM   #2
curryjon51
Registered User
 
Join Date: Jul 2003
Posts: 257
Default

Hi

You could try:
In the loadMeter function,change the this.onEnterFrame=fadeIn to this.onEnterFrame = locate

Then write your locate function with your positioning code etc, and at the end of that, put this.onEnterFrame = fadeIn

might work?
curryjon51 is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:51 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.