• User Attivo

    [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". image cosa c'è che non va???

    
    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


  • Super User

    Ciao,
    prova a mettere questa riga: c.load(file);
    alla fine


  • User Attivo

    @Flep said:

    prova a mettere questa riga: c.load(file);
    alla fine
    Ciao Flep,

    avevo già provato a mettere questa riga in fondo, ma il risultato sembra identico...:x

    Non so più cosa fare....Ma il codice che ho inviato secondo te è valido?

    Quando pubblico il filmato flash non mi appare nessun numero percentuale, se facio il debug movie la variabili botal è indefinita, mentre sembra non ci sia nessun problema con bloaded.
    :mmm:
    Ho rimodificato il codice così:

    
    var btotal:Number = c.getBytesTotal();
        
    _root.onEnterFrame = function() {
        var bloaded:Number = c.getBytesLoaded();
        if (bloaded <= btotal) {
    trace("Loaded "+bloaded+" of "+btotal+" bytes.");
    _root.fotoload.mytext2.text = Math.round(bloaded/btotal*100)+ "%";
        }}
    
    c.load(file);
    
    

    Grazie

    Sharemind


  • Super User

    Proviamo a dirgli:

    
    c.sendAndLoad(file,c,'POST');
    
    

    invece di c.load(file);


  • User Attivo

    Ciao,

    :o.......Niente anche con

    c.sendAndLoad(file,c,'POST');

    non ne vuol sapere...........:(

    btotal continua ad essere undefined....

    grazie

    Sharemind


  • Super User

    Controlla File>Impostazioni di Pubblicazione, sotto il tab di Flash che sia la versione 7 (al minimo) del player e la versione 2.0 di as.

    Il codice funziona (provato).;)


  • User Attivo

    ciao,

    ho controllato le impostazioni di pubblicazione ho flash 8 e versione 2.0 AS ....

    Scusa Onsitus hai detto che funziona? :arrabbiato:
    Ma come hai fatto?...Ho persino riprovato il codice in un nuovo filmato privo di tutto quello che non era necessario...........niente da fare ... stesso errore!!

    non so più che pesci prendere!

    Sharemind


  • Super User

    image

    :bho:


  • Super User

    Scusa ma il file php cosa restituisce ?


  • Super User

    @Onsitus said:

    image

    :bho:

    Screenshot sbagliato.:D

    image


  • User Attivo

    Penso di essere vicino alla soluzione......:fumato:

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

    http://forum.html.it/forum/showthread.php?s=&threadid=558471&highlight=loadva rs

    E' necessaio modificare il codice PHP inserendo header:
    [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();
    ?>
    [/php]

    Actionscript come segue:

    
    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();
    };
    

  • User Attivo

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

    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

     [LEFT]```
    

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

        
     
    riga".$a."
    
         [LEFT]```
    "img\".$a;\r\necho $myresult;\r\n\r\nheader(\"Content-Length: \".ob_get_length());\r\nob_end_flush(); \r\n?>"
    ```[/LEFT]
        
     
    
    Mentre se eseguo da solo il PHP il risultato è giusto:
    
    [LEFT]```
    n=10&riga0=img0&riga1=img1&riga2=img2&riga3=img3&riga4=img4&riga5=img5&riga6=img6&riga7=img7&riga8=img8&riga9=img9
    

    Sharemind
    [/LEFT]