3 Replies Latest reply on Oct 10, 2006 1:36 AM by Miran Loncaric

    Problem with MP3player class... Please help me

    Miran Loncaric Level 1
      Hello.

      I'm working on this class for few days now and still not getting it to work properly.

      The problem is inside of for statement...
      all Arrays inside of it should be filled with correct data and all what I get from tracers is undefined.

      Well the AS code is attached at the bottom(for better view)...

      Sample XML code:

      <?xml version="1.0" encoding="iso-8859-1"?>
      <soundPlayer>
      <song
      _artist="Artist"
      _title="Name of song"
      _album="Album"
      _src="Sample.mp3"
      />
      </soundPlayer>


      And for using you just type in Flash:

      import com.mloncaric.*;
      //
      var sound:soundPlayer = new soundPlayer();
      //
      sound.loadXML("soundPlayer.xml");
      //
      play_btn.onRelease = function() {
      sound.playSong();
      };


      If anyone has any idea where is the problem please tell me (this is my first class so it is possible that I've done stupid mistake).

      Thanks for now!

      mloncaric
        • 1. Re: Problem with MP3player class... Please help me
          Level 7
          Your problem is that inside your onLoad you don't have scope to your arrays.
          Try the following. Also, while the compiler will auto-generate a constructor
          for you, it's really not good form. You should at least have an empty
          constructor like so:

          function SoundPlayer()
          {
          }

          And, FWIW, it's convention to capitalize the first letter of a class file:


          class com.blurredistinction.SoundPlayer {
          var xml:XML;
          var urls:Array;
          var artist:Array;
          var title:Array;
          var album:Array;
          var sound_obj:Sound;
          var index:Number = 0;
          //
          var isPlaying:Boolean = false;
          //
          function loadXML(targetXML:String) {
          //store a reference to the class for scope
          var clRef = this;
          xml = new XML();
          urls = new Array();
          this.artist = new Array();
          title = new Array();
          album = new Array();
          sound_obj = new Sound();
          //
          xml.ignoreWhite = true;
          //
          xml.onLoad = function(success:Boolean) {
          if (success) {
          var temp:Array = this.firstChild.childNodes;
          //
          for (var i:Number = 0; i<temp.length; i++) {
          clRef.artist.push(temp .attributes._artist);
          clRef.title.push(temp
          .attributes._title);
          clRef.album.push(temp .attributes._album);
          clRef.urls.push(temp
          .attributes._src);
          }
          }
          };
          //
          xml.load(targetXML);
          }
          //
          function playSong() {
          if (isPlaying == false) {
          sound_obj.start(0, 100);
          sound_obj.loadSound(urls[index], true);
          sound_obj.setVolume(100);
          isPlaying = true;
          }
          }
          }


          --
          Dave -
          Adobe Community Expert
          www.blurredistinction.com
          http://www.adobe.com/communities/experts/


          • 2. Re: Problem with MP3player class... Please help me
            Level 7
            PS - sorry, but I changed the domain to blurredistinction for testing so I
            could just toss it into my class folder. I meant to change it back to your
            before posting it, but forgot.

            --
            Dave -
            Adobe Community Expert
            www.blurredistinction.com
            http://www.adobe.com/communities/experts/


            • 3. Re: Problem with MP3player class... Please help me
              Miran Loncaric Level 1
              Thank you very much for your answer.

              I'll try this code and I'll let you know if its working(I'm sure it will).

              Thanks again.

              mloncaric