Je suis en train de réécrire le code ActionScript 3.0 d'un petit player MP3 en flash (swf).
Vous pouvez voir le player sur mon site de musique (en travaux)
Aujourd'hui je vais vous donner le code du preloader en ActionScript 3.0 :
Sur la première frame de votre scénario, créez un calque que vous nommerez Actions et ne mettez rien dessus.
Puis ouvrez le panneau Action (touche F9), et copiez-collez le code ci dessous....
//Play the wait animated icon
wait_mc.play();
//Listen the progress Event
this.
loaderInfo.
addEventListener(ProgressEvent.
PROGRESS , onLoadProgress
);
//Listen the end of progress
this.
loaderInfo.
addEventListener(Event.
COMPLETE, onLoadComplete
);
/**
* Update the progress bar.
*/
{
var bl
:int = event.
bytesLoaded;
var bt
:int = event.
bytesTotal;
var amountLoaded
:int =
Math.
floor((bl
/ bt
)*100);
trace(amountLoaded * 2);
progressWaitBar_mc.width = amountLoaded * 2;
trace(amountLoaded);
chargement.
text =
Math.
round(amountLoaded
) + "%";
}
/**
* Download achieved, display the MixTape MP3 Player
*/
function onLoadComplete
(event
:Event):void {
trace("Download Complete ! ");
gotoAndStop(2);
}
//Manage cache-control for new web browser
//Listen the EnterFrame event, if we enter into the first frame and the swf is totally downloaded
stage.
addEventListener(Event.
ENTER_FRAME, checkComplete
);
/**
* Display the MixTape MP3 Player if the swf file was retrieved from cache.
*/
function checkComplete
(event
:Event):void { //File was entirely downloaded
if ( LoaderInfo(this.
root.
loaderInfo).
bytesLoaded ==
LoaderInfo(this.
root.
loaderInfo).
bytesTotal ) { //Stop to listen
stage.
removeEventListener(Event.
ENTER_FRAME, checkComplete
);
trace("Cache Complete ! ");
gotoAndStop(2);
}
}
//Don't go to the next frame until I decide !
stop();
Si vous faites Ctrl+Entrée pour tester l'animation cela plantera car :
- vous n'avez pas le movie clip wait_mc (c'est une animation d'attente)
- vous n'avez le movie clip progressWaitBar_mc (c'est juste un rectangle avec un masque pour simulez une barre de progression)
- vous n'avez pas le textfield chargement (ou on fait avancer le pourcentage)
- vous n'avez pas de frame 2 (c'est là que vous mettrez votre animation)
En espérant vous avoir aidé, n'hésitez pas à demander de l'aide !!!