Visualizzazione dei risultati da 1 a 4 su 4

Discussione: loadSound()

  1. #1

    loadSound()

    ciao!! Ho un probleba con uno script:
    mi carico in delle varabili i nomi di alcuni mp3 che poi vorrei sentire con loadsound, il loadvars mi funziona perchè riesco a traccia re le variabili ma quando le richiamo con loadsound mi da undefined, è come se prima facessi il loadsound e poi arrivassero le variabili, ecco il codice:

    stop();
    var files:LoadVars = new LoadVars();
    files.load("song.txt");
    files.onLoad = function(success) {
    if (success) {
    output.text="riceve!!";
    file1 = files.file1
    trace(file1);
    }else{
    output.text="comunicazione interrotta";
    }
    }
    //files.load("song.txt");

    function song(){
    mySound = new Sound();
    trace("../songs/"+files.file1)
    mySound.loadSound("../songs/"+file1, true);
    control.onEnterFrame = function() {
    tot = mySound.getBytesTotal();
    loa = mySound.getBytesLoaded();
    if (loa != tot) {
    output.text = "loading... "+Math.round((loa/tot)*100)+"%";
    } else {
    output.text = "playing...";
    delete control.onEnterFrame;
    }
    };
    }
    song();
    ascolta.onRelease = function(){
    mySound.onSoundComplete = function(){
    mySound.start(0,9999);
    }
    output.text="ciao";
    }

    e questo è il trace:
    ../songs/undefined
    Error opening URL "file:///C//Inetpub/songs/undefined "
    oasisdoyouknowwhatimean.mp3

  2. #2
    Utente di HTML.it L'avatar di negatyve
    Registrato dal
    Feb 2001
    Messaggi
    9,479
    Le cose devono avvenire nella giusta sequenza. Prima verifichi il caricamento del nome del file, e solo dopo invochi la funzione che lo carica:

    codice:
    stop();
    var files:LoadVars = new LoadVars();
    files.onLoad = function(success)
    {
    	if (success) {
    		output.text = "riceve!!";
    		file1 = files.file1;
    		trace(file1);
    		song();
    	} else {
    		output.text = "comunicazione interrotta";
    	}
    };
    files.load("song.txt");
    function song()
    {
    	mySound = new Sound();
    	trace("../songs/" + files.file1);
    	mySound.loadSound("../songs/" + file1, true);
    	control.onEnterFrame = function()
    	{
    		tot = mySound.getBytesTotal();
    		loa = mySound.getBytesLoaded();
    		if (loa != tot) {
    			output.text = "loading... " + Math.round((loa / tot) * 100) + "%";
    		} else {
    			output.text = "playing...";
    			delete control.onEnterFrame;
    		}
    	};
    }
    ascolta.onRelease = function()
    {
    	mySound.onSoundComplete = function()
    	{
    		mySound.start(0, 9999);
    	};
    	output.text = "ciao";
    };

  3. #3
    grazie tantissime, avevo intuito ora ho capito!!!!!!

  4. #4
    Utente di HTML.it L'avatar di negatyve
    Registrato dal
    Feb 2001
    Messaggi
    9,479
    Originariamente inviato da amnesiac
    grazie tantissime, avevo intuito ora ho capito!!!!!!
    La perfetta essenza dell'imparare..

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.