Français   English


SlideShow en ActionScript

// CREATOR          Morel Sophie
// VERSION          1.0
// CREATED          Aout 2005
// SUMMARY          Créer un slide show




mcPhoto="X";

//taille du film
FilmHeight=500;
FilmWidth   =500;
boutonHeight=50;

tailleImage=450;//les images sont loader dans un carré de coté tailleImage
bord=10;//taille du bord blanc autour de l'image
ImageIndex=0;// pour parcourir le tableau d'image
pathToPics="images/";

fadeSpeed=3;/* vitesse pour les méthodes fade in et fade out */
DureeAffichage=2000;/* la photo va apparaitre pendant 2 secondes */


//////////////////////////////////////////////////////////////////////
// acces aux images

//////////////////////////////////////////////////////////////////////
//Recherche des données sur les images depuis le fichier gallery.xml
// fichier créer grace au script php BuildXml.php




_root.document=newXML();
_root.document.ignoreWhite=true;
_root.ImageArray=newArray();

//Extraire les données du fichier XML et lancer le slideshow depuis la
//fonction extractData
_root.document.onLoad=extractData;
_root.document.load("gallery.xml");
       
functionextractData(success){

    percent=(this.getBytesLoaded()/this.getBytesTotal())*100;
        if(!isNan(percent)){
          tfNewfield.text=percent+"% loaded";
        }else{
             tfNewfield.text="0% loaded";
        }
       
    if(percent==100){
        // charger le nom des images depuis le xml
        // dans le tableau _root.ImageArray
        numimages=this.firstChild.childNodes.length;
        for(i=0;i<numimages;i++){
            noeud=this.firstChild.childNodes[i].attributes.nomImage;
            _root.ImageArray.push(noeud);
        }
        /// Lancer le slideShow
        SlideShow(pathToPics+_root.ImageArray[ImageIndex]);
    }
}


functionSlideShow(image_path){
    ///////////////////////////////////////////////////////////////////
    // création de movieClip support de l'image à afficher
   
    /* Loader l'image à afficher */
    this.createEmptyMovieClip(mcPhoto,4);
    loadMovie(image_path,this[mcPhoto]);
   
    _root[mcPhoto]._alpha=0;
   
    /////////////////////////////////////////////////////////////////////////////
    /////////////////////       this.onEnterFrame   
               
    this.onEnterFrame=function(){
       
        //trace the percentage of the movie that has loaded
        percent=(this[mcPhoto].getBytesLoaded() / this[mcPhoto].getBytesTotal())*100;
        if(!isNan(percent)){
        // tfNewfield.text =percent+ " % loaded";
        }else{
             //tfNewfield.text =" 0% loaded";
        }
       
        // si l'image est complétement loader, on peut la transformer
         if(percent==100){
       
            /* definir une taille approprié pour l'affichage */
            /* l'image doit tenir dans un carré de coté tailleImage */
           
            if(this[mcPhoto]._width>this[mcPhoto]._height){
                this[mcPhoto]._height=(tailleImage*this[mcPhoto]._height) / this[mcPhoto]._width;
                this[mcPhoto]._width=tailleImage;
            }
            else{
                this[mcPhoto]._width=(tailleImage*this[mcPhoto]._width) / this[mcPhoto]._height;
                this[mcPhoto]._height=tailleImage;
            }
           
            /* centrer l'image en fonction de sa taille et sa hauteur et de la taille du Movie */
           
            this[mcPhoto]._x+=(FilmHeight-this[mcPhoto]._width)/2;
                this[mcPhoto]._y+=(FilmHeight-this[mcPhoto]._height)/2;
           
           
            //////////////////////////////////////////////////
            // ajouter un bord blanc autour de la photo
           
            this.createEmptyMovieClip("mcBord",2);
            with(this.mcBord){
                lineStyle(1,"0xAAAAAA", 100);
                                   beginFill(0xFFFFFF,100);
                                   moveTo(-bord,-bord);
                                   lineTo(bord+this[mcPhoto]._width,-bord);
                                   lineTo(bord+this[mcPhoto]._width,this[mcPhoto]._height+bord);
                                   lineTo(-bord,this[mcPhoto]._height+bord);
                                   lineTo(-bord,-bord);
                                   endFill();
                _alpha=0;
               
            }
           
            /* positionner le bord blanc pour encadrer l'image */
            this.mcBord._x=this[mcPhoto]._x;
            this.mcBord._y=this[mcPhoto]._y;
   
           
            /* fade in méthode pour afficher l'image */
            /* affichage pendant DureeAffichage puis fade out */
                            fadeIn(fadeSpeed);
       

            // affichage de l'image terminé        
                        deletethis.onEnterFrame;
      }
    };

}
/////////////////////////////////////////////////////////////////////////////
/////////          Fonction fadeIn fadeOut et Affichage
functionfadeIn(fadeSpeed){

    _root[mcPhoto].onEnterFrame=function(){
        mcBord._alpha+=fadeSpeed;
         this._alpha+=fadeSpeed;
         if(this._alpha>=100){
            affImage=setInterval(Affichage,DureeAffichage,fadeSpeed);
                               deletethis.onEnterFrame;
         }
    };
                                                      
}

functionAffichage(DureeAffichage){
    fadeOut(fadeSpeed);
    clearInterval(affImage);
   
}


functionfadeOut(fadeSpeed){

    _root[mcPhoto].onEnterFrame=function(){
         if(_root[mcPhoto]._alpha>0){
            this._alpha-=fadeSpeed;
            mcBord._alpha-=fadeSpeed;
         }
        else{
            
            ImageIndex+=1;
            if(ImageIndex>=ImageArray.length)
                ImageIndex=0;
           
            //relancer le slideshow pour la prochaine image
            SlideShow(pathToPics+ImageArray[ImageIndex]);
               
               
            deletethis.onEnterFrame;
        }
    };                                                                                                                                                                                                                                                                                                           
                                                                 
}


// Fin du script