Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    [F8] getBytesLoaded loadVars preload

    salve,

    vorrei creare un preload mentre flash carica i dati da un file in php.

    C'è qualcuno che sa dirmi come faccio ad usare il metodo getBytesLoaded e getBytesTotal con loadVars?

    Ho provato con questo codice(actionscript 2.0), ma come risultato di getBytesLoaded ho ottenuto "undefined". cosa c'è che non va???

    codice:
    stop();
    file = 'http://www.pippo.com/pluto.php';
    c = new LoadVars();
    
    c.onLoad = function(success){    
        if(success){
        root.mytext._visible=false;
            play();
        } else root.mytext..text="Errore nel caricare le immagini";
    }
    
    c.load(file);
    
    _root.onEnterFrame = function() {
        var bloaded:Number = c.getBytesLoaded();
        var btotal:Number = c.getBytesTotal();
        if (bloaded >= btotal) {
        trace("Loaded "+lvBytesLoaded+" of "+lvBytesTotal+" bytes.");
       _root.mytext.text = Math.round(bloaded ()/btotal()*100)+ "%"
        }
    }
    grazie
    Sharemind

  2. #2
    Forse ho trovato la soluzione......

    http://www.actionscript.it/forum/showthread.php?t=9058


    http://forum.html.it/forum/showthrea...ghlight=loadva rs

    E' necessaio modificare il codice PHP inserendo header:
    Codice PHP:
    Codice PHP:
    <?
    $myresult
    ="n=10";
    ob_start();  

    for(
    $a=0;$a<10;$a++)
        
    $myresult.="&riga".$a."=img".$a;
    echo 
    $myresult;

    header("Content-Length: ".ob_get_length());
    ob_end_flush();  
    ?>
    Actionscript come segue:
    Codice:


    codice:
    LoadVars.prototype.checkHeader = function() {
    	this.idHeader = setInterval(this, "getTotal", 10);
    };
    LoadVars.prototype.getTotal = function() {
    	if (this.getBytesTotal() != undefined) {
    		this.onStart();
    		this.idLoading = setInterval(this, "getLoading", 10);
    		clearInterval(this.idHeader);
    	}
    };
    LoadVars.prototype.getLoading = function() {
    	this.onLoadProgress();
    	if (this.getBytesLoaded()>=this.getBytesTotal()) {
    		clearInterval(this.idLoading);
    	}
    };
    this.preload._visible = false;
    result = new LoadVars();
    result.load("prova.php");
    result.checkHeader();
    result.onLoadProgress = function() {
    	_root.textField3.text = "caricati: "+this.getBytesLoaded();
    	_root.textField4.text = "totali: "+this.getBytesTotal();
    };
    result.onStart = function() {
    	this.startTime = getTimer();
    	_root.textLabel1.text = "inizio flusso";
    	_root.preload.loadVarsObject = this;
    	_root.preload.totalBytes = this.getBytesTotal();
    	_root.preload.onEnterFrame = function() {
    		this.loadedBytes = this.loadVarsObject.getBytesLoaded();
    		this.percent = this.loadedBytes/this.totalBytes*100;
    		this.barra._xscale = this.percent;
    		this._visible = true;
    		this.text1.text = "Percentuale: "+Math.round(this.percent)+"%";
    		this.text2.text = "Bytes caricati: "+this.loadedBytes;
    		if (this.loadedBytes == this.totalBytes) {
    			delete this.onEnterFrame;
    		}
    	};
    };
    result.onLoad = function() {
    	_root.prova.text=result["n"];
    	_root.textLabel2.text = "fine flusso, bytes scaricati: "+this.getBytesLoaded()+" in "+(getTimer()-this.startTime)+"ms";
           //play();
    };
    Sharemind

  3. #3
    Ho provato con gli esempi sopra riportati, ma ho dei problemi a farli funzionare.

    C'è qualcuno che puo' darmi una mano?

    Il preloader funziona, il filmato visualizza la percentuale caricata ed al termine esegue le istruzioni all'interno della funzione onLoad.

    Il problema è che flash interpreta in modo sbagliato i dati passati dal file PHP:

    Se eseguo il debug da flash ottengo:

    <?$myresult

    codice:
    "\"n=10\";\r\nob_start(); \r\n\r\nfor($a=0;$a<10;$a )\r\n\t$myresult.=\""
    riga".$a."

    codice:
    "img\".$a;\r\necho $myresult;\r\n\r\nheader(\"Content-Length: \".ob_get_length());\r\nob_end_flush(); \r\n?>"
    Mentre se eseguo da solo il PHP il risultato è giusto:

    codice:
    n=10&riga0=img0&riga1=img1&riga2=img2&riga3=img3&riga4=img4&riga5=img5&riga6=img6&riga7=img7&riga8=img8&riga9=img9
    Sharemind

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.