A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 29

Thread: Variables in loading a music file

  1. #1
    Senior Member
    Join Date
    Sep 2004
    Posts
    113

    Variables in loading a music file

    I am trying to load a file which i assined using a variable

    here is my AS:
    PHP Code:
    file _level0.id;
    loadVariables("file.php?id="+file"_root");
    myMusic = new Sound(myMusicMc);
    myMusic.loadSound("../songuploads/song1.mp3");
    //myMusic.loadSound("../root/soundfiles/"+file); 
    But it only loads when i explicity say the location

    What shall I do?

  2. #2
    5+5=55 Schfifty Five's Avatar
    Join Date
    Jun 2006
    Posts
    698
    Try tracing _level0.id to see what you get.

  3. #3
    Senior Member
    Join Date
    Sep 2004
    Posts
    113
    i get the name of the file that should be played

    i know the variable works fine becuase i have it displayed in a textbox

  4. #4
    Get Squared Away.
    Join Date
    Feb 2000
    Location
    Allentown, PA
    Posts
    543
    try defining file = _root.id on a frame before you make the loadVariables call...
    this could be an issue of id being undefined when loadVariables gets called.

  5. #5
    Senior Member
    Join Date
    Sep 2004
    Posts
    113
    The variable is being defined and retreived properly.

    What I am having trouble with is getting it to load:

    myMusic.loadSound("../soundfiles/"+file);

  6. #6
    Get Squared Away.
    Join Date
    Feb 2000
    Location
    Allentown, PA
    Posts
    543
    did you try something like:

    myMusic.loadSound("../soundfiles/song"+file+".mp3");

  7. #7
    Senior Member
    Join Date
    Sep 2004
    Posts
    113
    the varaible file contains "song1.mp3" so I don't need to do so.

  8. #8
    Senior Member
    Join Date
    Sep 2004
    Posts
    113
    is there a way I can debug it and see the variables in real-time in the browser?

  9. #9
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    the issue is timing

    you load via loadVariables and a nano-second later you try to use the variable
    it will always fail (even though you can see the variable in a textfield)

    use a loadvars object, it has an onLoad function that runs when all
    data has completed loading

  10. #10
    Senior Member
    Join Date
    Sep 2004
    Posts
    113
    what do you mean by:

    use a loadvars object, it has an onLoad function that runs when all
    data has completed loading
    Would putting it on a diffrent frame work?

  11. #11
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176

  12. #12
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    Code:
    file = _level0.id; 
    myMusic = new Sound(myMusicMc);
    
    sv = new LoadVars(); // send object
    sv.id = file;
    lv = new LoadVars(); // load object
    sv.sendAndLoad("file.php", lv, "POST"); 
    
    lv.onLoad = function(){ 
    trace(lv.file); // php should return - file=song1.mp3
    myMusic.loadSound("../root/soundfiles/"+lv.file); 
    };
    this might work

  13. #13
    Senior Member
    Join Date
    Sep 2004
    Posts
    113
    thank you very much for that.

    I have one more question.

    How do I stop it after 15 seconds of playing?

  14. #14
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    use setInterval to check the sound.position property -
    Code:
    function checker(){
    trace(myMusic.position);
    if(myMusic.position > 15000){
    myMusic.stop();
    clearInterval(posINT);
    }
    };
    
    lv.onLoad = function(){ 
    myMusic.loadSound("../root/soundfiles/"+lv.file, true); 
    posINT = setInterval(checker,500);
    };

  15. #15
    Senior Member
    Join Date
    Sep 2004
    Posts
    113
    Sorry for the late reply but I have only managed to try and put it all together and it doesn't seem to work.

    This is what I have at the moment:

    Code:
    file = _level0.id; 
    myMusic = new Sound(myMusicMc);
    
    sv = new LoadVars(); // send object
    sv.id = file;
    lv = new LoadVars(); // load object
    sv.sendAndLoad("file.php", lv, "GET");
    
    
    lv.onLoad = function(){ 
    trace(lv.file); // php should return - file=song1.mp3
    myMusic.loadSound("../soundfiles/"+lv.file); 
    songstat = "Ready to play "+lv.file;
    };
    The reason I am using get is becuase the URL for getting the file name is file.php?id=1

    and the output is
    file=song1.mp3
    Where Am I going wrong? I went through it over 5 times and I still can't see.

    Thanks and sorry again for bumping the thread up

  16. #16
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    loadSound accepts 2 parameters -

    url of sound file
    boolean true/false -- true is streaming, false is event

    Streaming sounds play while they are downloading
    Event sounds are completely loaded before they can be played

    If the second parameter is omitted, it defaults to false.

    I ran a simple test with a text file and a button to start the sound -
    Code:
    this.createEmptyMovieClip("myMusic",1000);
    myMusic = new Sound(myMusicMc);
    
    lv = new LoadVars();
    lv.load("song.txt");
    
    lv.onLoad = function(){ 
    myMusic.loadSound(lv.file); // defaults to event sound
    trace("Ready to play "+lv.file);
    };
    
    /*--song.txt--
    &file=song1.mp3&
    */
    
    btn.onRelease = function(){
    myMusic.start();
    };

  17. #17
    Senior Member
    Join Date
    Sep 2004
    Posts
    113
    OK I see

    but how can i integrate this with PHP?

    Please have a look at the fla and see where i am going wrong.
    Attached Files Attached Files

  18. #18
    Senior Member
    Join Date
    Sep 2004
    Posts
    113
    can anyone have a look at the file and tell me where I am going wrong?

  19. #19
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    but how can i integrate this with PHP?

    i used a variable from a text file to test
    you must get your php to return the variable -

    &file=song1.mp3&

  20. #20

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center