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
|
package {
//import
import flash.display.MovieClip;//a voir pour le modifier par sprite...
import flash.display.Shape;
import flash.display.Loader;
import flash.text.TextField;
import flash.filters.GlowFilter;
import flash.net.URLRequest;
import flash.errors.IOError;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.ProgressEvent;
[SWF( width='600',height='400',frameRate='30',backgroundColor='#000000')]
public class Preloader extends MovieClip {
//_______________________________________________constantes:
private const _couleur :uint = 0xFF0000;
private const _adresse :String = "data/images/design_site_perso.jpg";
//________________________________________________variables:
private var _filtre :GlowFilter;
private var _barreCharge :MovieClip;
private var _infos :TextField;
private var _barre :Shape;
private var _loader :Loader;
private var _req :URLRequest;
private var _centreY :int;
//____________________________________________constructeurs:
public function Preloader():void {
_barreCharge = new MovieClip();
_infos = new TextField();
_barre = new Shape();
_loader = new Loader();
_filtre = new GlowFilter(_couleur,1,10,10,1,3,false,false);
_req = new URLRequest(_adresse);
_infos.textColor = _couleur;
_infos.width = 28;
_centreY = stage.stageHeight/2;
_barre.graphics.beginFill(_couleur);
_barre.graphics.drawRect(0,stage.stageHeight/2,1,4);
_barreCharge.filters = [_filtre];
this.addChild(_barreCharge);
this.addChild(_infos);
this._barreCharge.addChild(_barre);
_loader.load(_req);
_loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, $avancement);
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, $chargementTermine);
_loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, $erreur);
}
//_______________________________________________methodes:
public function $avancement(evt:ProgressEvent):void {
var _pct:uint = Math.round(evt.bytesLoaded/evt.bytesTotal * 100);
_infos.text = _pct + "%"
_infos.y = _centreY + 5;
_infos.x = _barreCharge.x + _barreCharge.width + 5;
_barreCharge.width =stage.stageWidth / 100 * _pct;
}
public function $chargementTermine(evt:Event):void {
_loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, $avancement);
_loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, $chargementTermine);
_loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, $erreur);
this.removeChild(_infos);
this.removeChild(_barreCharge);
_infos = null;
_barreCharge = null;
this.addChild(_loader);
}
public function $erreur(evt:Event):void {
_loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, $avancement);
_loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, $chargementTermine);
_loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, $erreur);
this.removeChild(_barreCharge);
_barreCharge = null;
_infos.text = "Erreur de Chargement...";
_infos.width = 150;
_infos.y = _centreY;
_infos.x = stage.stageWidth - _infos.width/2;
}
}//end of class
}//end of package |
Partager