11 Replies Latest reply on Jul 3, 2007 1:58 PM by kglad

    problem loading mp3's

    masterkrang
      //anybody know why the code below won't work? the problem is not LoadVars, because those are loading fine.
      //the problem seems to be when i send a string variable to the loadSound method from within the onLoad that the song
      //will not play. song play fine if i tell them to play outside onLoad function.
      //any suggestions?
      //thanks!


      var loadSongs:LoadVars = new LoadVars();

      loadSongs.onLoad = function(success:Boolean) {
      if (success) {

      theSongs.text = "1. " + loadSongs.one +
      "\n2. " + loadSongs.two +
      "\n3. " + loadSongs.three +
      "\n4. " + loadSongs.four +
      "\n5. " + loadSOngs.five;

      var firstSong:String = loadSongs.one;

      //play the first song
      var mysound:Sound = new Sound();
      mysound.loadSound(firstSong, true);
      mysound.start();

      } else {
      //do somehting else
      }

      }
      loadSongs.load("test.php");
        • 1. Re: problem loading mp3's
          masterkrang Level 1
          //in case this is important: the url string that is currently being returned to the //LoadVars object is:

          &one=Allegory of Atonement.mp3&two=Deadpool.mp3&three=Scorn.mp3&four=Silent.mp3&five=Virtue in Devourment.mp3
          • 2. Re: problem loading mp3's
            kglad Adobe Community Professional & MVP
            is your loadSound statement in (the scope) of loadSongs.onLoad? if not, remove the var prefix of firstSong and don't type it as String.
            • 3. Re: problem loading mp3's
              masterkrang Level 1
              i don't think i'm following exactly what you mean.... the loadSound statement is within the scope of loadSongs.onLoad.

              i tried taking the va prefix off of firstSong and didn't type it as a string, still not getting loadSound to work.

              i've even tried sending the string variable to a function playTheFirstSong that was define outside of onLoad, but that wouldn't work. thanks for the help, still having trouble.
              • 4. Re: problem loading mp3's
                kglad Adobe Community Professional & MVP
                copy and paste your loadSongs.onLoad method add trace(firstSong) just after mysound.loadSound and paste the results of that trace statement.
                • 5. Re: problem loading mp3's
                  masterkrang Level 1
                  var loadSongs:LoadVars = new LoadVars();

                  loadSongs.onLoad = function(success:Boolean) {
                  if (success) {

                  theSongs.text = "1. " + loadSongs.one +
                  "\n2. " + loadSongs.two +
                  "\n3. " + loadSongs.three +
                  "\n4. " + loadSongs.four +
                  "\n5. " + loadSOngs.five;

                  var firstSong:String = loadSongs.one;

                  //play the first song
                  var mysound:Sound = new Sound();
                  mysound.loadSound(firstSong, true);
                  trace_text.text = "the firstSong var traced out: " + firstSong;
                  mysound.start();

                  } else {
                  //do somehting else
                  }

                  }
                  loadSongs.load("test.php");


                  //so i just traced the var firsSong to a text field called trace_text.text
                  //see the results here

                  http://serpentsociety.com/deadmachine/serpent_mp3_player.swf

                  • 6. Re: problem loading mp3's
                    kglad Adobe Community Professional & MVP
                    1. check for upper/lower case mismatches in your file named Allegory of Atonement.mp3

                    2. if there are no mismatches, rename it Allegory_of_Atonement.mp3 and change your php file to return Allegory_of_Atonement.mp3.

                    3. retest.
                    • 7. Re: problem loading mp3's
                      kglad Adobe Community Professional & MVP
                      oops, one more thing before you try #2:

                      check for whitespace after Allegory of Atonement.mp3. ie, check firstSong.length and see if it matches 25.
                      • 8. Re: problem loading mp3's
                        masterkrang Level 1
                        so i tried both of your suggestions and they didn't work. view the file at:
                        http://serpentsociety.com/deadmachine/serpent_mp3_player.swf
                        i output the length of the string.

                        this is the current state of the code:

                        var loadSongs:LoadVars = new LoadVars();

                        loadSongs.onLoad = function(success:Boolean) {
                        if (success) {

                        theSongs.text = "1. " + loadSongs.one +
                        "\n2. " + loadSongs.two +
                        "\n3. " + loadSongs.three +
                        "\n4. " + loadSongs.four +
                        "\n5. " + loadSongs.five;

                        var firstSong:String = loadSongs.one;

                        //play the first song
                        var mysound:Sound = new Sound();
                        mysound.loadSound(firstSong, true);
                        trace_text.text = "the firstSong var traced out: " + firstSong + " \nlength: " + firstSong.length;
                        mysound.start();



                        } else {
                        //do somehting else
                        }

                        }
                        loadSongs.load("test.php");

                        /* one strange this is that if i give the mySound.loadSound method a literal string it will also not play */

                        example:

                        var loadSongs:LoadVars = new LoadVars();

                        loadSongs.onLoad = function(success:Boolean) {
                        if (success) {

                        theSongs.text = "1. " + loadSongs.one +
                        "\n2. " + loadSongs.two +
                        "\n3. " + loadSongs.three +
                        "\n4. " + loadSongs.four +
                        "\n5. " + loadSongs.five;

                        var firstSong:String = loadSongs.one;

                        //play the first song
                        var mysound:Sound = new Sound();
                        mysound.loadSound("Deadpool.mp3", true);
                        trace_text.text = "the firstSong var traced out: " + firstSong + " \nlength: " + firstSong.length;
                        mysound.start();



                        } else {
                        //do somehting else
                        }

                        }
                        loadSongs.load("test.php");

                        /*yet if i pull the loadSound method entirely out of the onLoad function, AND if i give the onLoad method a string literal, the song WILL play!? */

                        /*example*/

                        var loadSongs:LoadVars = new LoadVars();

                        loadSongs.onLoad = function(success:Boolean) {
                        if (success) {

                        theSongs.text = "1. " + loadSongs.one +
                        "\n2. " + loadSongs.two +
                        "\n3. " + loadSongs.three +
                        "\n4. " + loadSongs.four +
                        "\n5. " + loadSongs.five;

                        var firstSong:String = loadSongs.one;

                        //play the first song




                        } else {
                        //do somehting else
                        }

                        }
                        loadSongs.load("test.php");

                        var mysound:Sound = new Sound();
                        mysound.loadSound("Deadpool.mp3", true);
                        //trace_text.text = "the firstSong var traced out: " + firstSong + " \nlength: " + firstSong.length;
                        mysound.start();

                        /*this works!*/

                        • 9. Re: problem loading mp3's
                          masterkrang Level 1
                          just in case something might be lost in translation of my php script, i output the result to the browser. view that here:

                          http://serpentsociety.com/deadmachine/test.php

                          the php code is pretty straight forward as well:

                          <?php

                          $numSongs = 1;
                          //$songNumStr = ' ';

                          //echo phpinfo();
                          foreach (glob("*.mp3") as $filename) {
                          switch($numSongs){
                          case 1: $songNumStr = "one";
                          break;
                          case 2: $songNumStr = "two";
                          break;
                          case 3: $songNumStr = "three";
                          break;
                          case 4: $songNumStr = "four";
                          break;
                          case 5: $songNumStr = "five";
                          break;
                          default: echo "no songs";
                          }
                          echo $filename.'<br />'; //size " . filesize($filename) . "<br />";
                          $MPThreeStr.= '&'.$songNumStr.'='.$filename;
                          $numSongs++;

                          }
                          echo $MPThreeStr;
                          ?>
                          • 11. Re: problem loading mp3's
                            kglad Adobe Community Professional & MVP
                            what's

                            trace_text.text = "the firstSong var traced out: "+firstSong+" \nlength: "+firstSong.length;

                            reveal?