Home » AS3 »Avanzado » Currently Reading:

Ejemplo de Preload en Actioncsript 3

noviembre 5, 2006 AS3, Avanzado 2 Comments
Ejemplo de Preload en Actioncsript 3

Esta clase que he montado permite crear un sencillo preload para la linea de tiempo principal de un swf en AS3.

package preloads
{
    import flash.display.Stage;
    import flash.display.MovieClip;
    import flash.display.Shape;
    import flash.text.TextField;
    import flash.events.*
    //——————————————–
    public class PreloadBasico extends MovieClip
    {
        private var texto:TextField;
        private var marco:Shape;        
        private var barra:Shape;
        //—————————————-
        public function PreloadBasico ()
        {   
            dibujaPreload();
            posicionaPreload();
            this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, onLoadProgress);
            this.loaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);        
            //—————————————-
            function onLoadProgress (event:ProgressEvent):void
            {
                var cargado:int = event.bytesLoaded;
                var total:int = event.bytesTotal;
                var porcentaje:int = cargado/total*100;
                texto.text = "Cargado: "+String(porcentaje)+"%";
                barra.width = porcentaje*marco.width/100;
            }
            //—————————————-
            function onLoadComplete (event:Event):void
            {
                removeChild(texto);
                removeChild(marco);
                removeChild(barra);
                nextFrame();
            }
            //—————————————-
        }
        //—————————————-
        public function dibujaPreload() {
            texto = new TextField();
            marco = new Shape();
            barra = new Shape();
            marco.graphics.lineStyle(1, 0x000000);
            marco.graphics.drawRoundRect(0, 20, 70, 5, 0);
             barra.graphics.beginFill(0x000000);
             barra.graphics.drawRect(0, 20, 70, 5);
             barra.graphics.endFill();    
            addChild(texto);
            addChild(marco);
            addChild(barra);
        }
        //—————————————-
        public function posicionaPreload() {
            texto.x = marco.x = barra.x = stage.stageWidth /2 – marco.width /2
            texto.y = stage.stageHeight /2 – texto.height /2
            marco.y = barra.y = texto.y + 5
        }
        //—————————————-
    }
}

En el foro de cristalab escribí un poco de explicación de su uso, asi que no volveré a escribirlo U_U. Podeis encontrarla aqui.

Y aqui el ejemplo.

Compártelo:

Ejemplo de Preload en Actioncsript 3
Visto 14.550 veces

Currently there are "2 comments" on this Article:

  1. Jorge dice:

    Hola, funciona de maravilla, pero algo extraño que note fue que cuando se actualiza la página, no se muestra la animacion sino se queda mostrando solo la barra del preloader al 100%.

  2. francisco dice:

    Hola jorge, para que no te pase eso pon en el primer frame de tu animación:
    if(this.loaderInfo.bytesLoaded == this.loaderInfo.bytesTotal)
    this.nextFrame();

Comment on this Article:








Twitter: zguillez

AdvertisementAdvertisementAdvertisementAdvertisement

Recibe las novedades por email



Map

Ranking

Codigoactionscript.org: 4.65 sobre 5 (106 valoraciones)

twitter-widget.com