1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
| import flash.display.Loader;
import flash.events.MouseEvent;
import flash.net.URLRequest;
import flash.utils.Timer;
const NBIMAGE = 3;//définition du nombre d'image
var compteur:Number = 0;//compte les images
var arrayPicture:Array = new Array();//contient les url et titres des images
arrayPicture.push(new Array("image1.jpg","titre1"));
arrayPicture.push(new Array("image2.jpg","titre2"));
arrayPicture.push(new Array("image3.jpg","titre3"));
/*Chrono pour lancer le changement d'image*/
var chrono:Timer = new Timer(3500);
var chrono2:Timer = new Timer(5);
var chrono3:Timer = new Timer(5);
chrono.start();
chrono.addEventListener(TimerEvent.TIMER,changeImageTime);
/*création du loader*/
var image:URLRequest = new URLRequest(arrayPicture[compteur][0]);
var myLoader:Loader = new Loader();
var imgDisplay:MovieClip = new MovieClip();// imgDisplay permet de formater la taille du Loader
myLoader.load(image);
myLoader.x = 0;
myLoader.y = 0;
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,charge); // demande la fin du chargement avant d'executer
/*Création de la barre inférieure grise*/
var mcFondTexte : FondTexte = new FondTexte();
mcFondTexte.y = 221;
stage.addChild(mcFondTexte);
/*Création du textField pour le titre de l'image*/
var formatSimple:TextFormat = new TextFormat();//création d'un format que l'on appliquera ensuite au textField
formatSimple.font = "Calibri";
formatSimple.size = 16;
var titre:TextField = new TextField();//Création d'une zone de texte
titre.height = 75;//hauteur
titre.width = 650;//largeur
titre.defaultTextFormat = formatSimple;//on applique le format au textField
titre.x=50;//Positionnement
titre.y=221;
stage.addChild(titre);//Ajout sur la scene
/*Création des boutons et positionnement*/
var mcBouton1 : Bouton = new Bouton();
mcBouton1.x = 520;
mcBouton1.y = 255;
var mcBouton2 : Bouton = new Bouton();
mcBouton2.x = 556;
mcBouton2.y = 255;
var mcBouton3 : Bouton = new Bouton();
mcBouton3.x = 594;
mcBouton3.y = 255;
mcBouton1.numero = 0;//ce numero sert à récupérer la valeur du bouton cliqué
mcBouton2.numero = 1;
mcBouton3.numero = 2;
stage.addChild(mcBouton1);//Ajouts sur la scene
stage.addChild(mcBouton2);
stage.addChild(mcBouton3);
/*Boutons "cliqués" => Création et positionnement*/
var mcBoutonCLICK1 : BoutonCLICK = new BoutonCLICK();
mcBoutonCLICK1.x = 520;
mcBoutonCLICK1.y = 255;
mcBoutonCLICK1.alpha = 1;
var mcBoutonCLICK2 : BoutonCLICK = new BoutonCLICK();
mcBoutonCLICK2.x = 556;
mcBoutonCLICK2.y = 205;
mcBoutonCLICK2.alpha = 0;
var mcBoutonCLICK3 : BoutonCLICK = new BoutonCLICK();
mcBoutonCLICK3.x = 594;
mcBoutonCLICK3.y = 205;
mcBoutonCLICK3.alpha = 0;
stage.addChild(mcBoutonCLICK1);
stage.addChild(mcBoutonCLICK2);
stage.addChild(mcBoutonCLICK3);
function changeImageTime(evt:TimerEvent)
{
/*Cette fonction lancée par chrono déplace le rond blanc lors du changement d'image et lance decreaseAlpha*/
if(compteur == (NBIMAGE-1))//permet au slider de boucler.
compteur = 0;
else
compteur++;
/*gestion couleur bouton*/
if(compteur==0)
{
mcBoutonCLICK1.alpha = 1;
mcBoutonCLICK1.y=255;
mcBoutonCLICK2.alpha = 0;
mcBoutonCLICK2.y-=50;
mcBoutonCLICK3.alpha = 0;
mcBoutonCLICK3.y-=50;
}
else if(compteur==1)
{
mcBoutonCLICK1.alpha = 0;
mcBoutonCLICK1.y-=50;
mcBoutonCLICK2.alpha = 1;
mcBoutonCLICK2.y=255;
mcBoutonCLICK3.alpha = 0;
mcBoutonCLICK3.y-=50;
}
else if(compteur==2)
{
mcBoutonCLICK1.alpha = 0;
mcBoutonCLICK1.y-=50;
mcBoutonCLICK2.alpha = 0;
mcBoutonCLICK2.y-=50;
mcBoutonCLICK3.alpha = 1;
mcBoutonCLICK3.y=255;
}
chrono3.start();
chrono3.addEventListener(TimerEvent.TIMER,decreaseAlpha);
}
function charge(evt:Event)
{
/*Cette fonction se lance une fois qu'une image est chargée dans le Loader.
Elle formate l'image -> la taille et la transparence ( à 0 )*/
this.addChild(imgDisplay);
imgDisplay.addChild(myLoader);
imgDisplay.alpha = 0;
imgDisplay.width = 650;
imgDisplay.height = 221;
chrono2.start();
chrono2.addEventListener(TimerEvent.TIMER,increaseAlpha);//lance la procédure d'apparition de l'image
titre.text = arrayPicture[compteur][1];//affiche le titre de l'image
}
/*modification transparence*/
function increaseAlpha(evt:TimerEvent)
{
/*Augmente petit à petit l'oppacité de l'image*/
imgDisplay.alpha += 0.05;
if(imgDisplay.alpha >= 1)
{
chrono2.removeEventListener(TimerEvent.TIMER,increaseAlpha);
chrono2.stop();
}
}
function decreaseAlpha(evt:TimerEvent)
{
/*Augmente petit à petit la transparence de l'image*/
imgDisplay.alpha -= 0.05;
if(imgDisplay.alpha <= 0)
{
chrono3.removeEventListener(TimerEvent.TIMER,decreaseAlpha);
chrono3.stop();
myLoader.unload();
image = new URLRequest(arrayPicture[compteur][0]);//changement d'image
myLoader.load(image);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,charge);
chrono3.stop();
chrono3.removeEventListener(TimerEvent.TIMER,decreaseAlpha);
}
}
function allerTableau(evt:MouseEvent)
{
/*Permet à l'internaute de changer d'image via les boutons*/
compteur = evt.target.numero;// récupère quel numéro de bouton a été cliqué
if(compteur==0)
{
mcBoutonCLICK1.alpha = 1;
mcBoutonCLICK1.y=255;
mcBoutonCLICK2.alpha = 0;
mcBoutonCLICK2.y-=50;
mcBoutonCLICK3.alpha = 0;
mcBoutonCLICK3.y-=50;
}
else if(compteur==1)
{
mcBoutonCLICK1.alpha = 0;
mcBoutonCLICK1.y-=50;
mcBoutonCLICK2.alpha = 1;
mcBoutonCLICK2.y=255;
mcBoutonCLICK3.alpha = 0;
mcBoutonCLICK3.y-=50;
}
else if(compteur==2)
{
mcBoutonCLICK1.alpha = 0;
mcBoutonCLICK1.y-=50;
mcBoutonCLICK2.alpha = 0;
mcBoutonCLICK2.y-=50;
mcBoutonCLICK3.alpha = 1;
mcBoutonCLICK3.y=255;
}
image = new URLRequest(arrayPicture[compteur][0]);//nouvelle image à charger
myLoader.load(image);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, charge);//lancement de la fonction charge
/*chrono de changement d'image remis à jour*/
chrono.stop();
chrono.removeEventListener(TimerEvent.TIMER,changeImageTime);
chrono.start();
chrono.addEventListener(TimerEvent.TIMER,changeImageTime);
}
/*Listener sur les boutons*/
mcBouton1.addEventListener(MouseEvent.CLICK, allerTableau);
mcBouton2.addEventListener(MouseEvent.CLICK, allerTableau);
mcBouton3.addEventListener(MouseEvent.CLICK, allerTableau); |
Partager