1 Reply Latest reply on Jul 28, 2007 9:21 PM by MatthewFord

    new to actionscript...call to undefined method

    elduuderin0
      HI Guys,

      IM really new to to flash and actionscript. Ive got a version of the news cs3 flash and am following a tut to make an xml driven mp3 player. Ive followed it to the t but when i go to test movie ( i dont know if thats the best way to see if ti works or not) i get some errors.

      I basically get these errors:
      1061: Call to a possibly undefined method loadSound through a reference with static type flash.media:Sound.
      1061: Call to a possibly undefined method loadSound through a reference with static type flash.media:Sound.
      1061: Call to a possibly undefined method loadSound through a reference with static type flash.media:Sound.

      with this code:

      Actionscript Code:

      //set up sound object
      var s:Sound = new Sound();
      s.onSoundComplete = playSong;
      s.setVolume(75);

      //Array of songs
      var sa:Array = new Array();

      //Current playing song
      var cps:Number = -1;

      //Load the songs XML
      var Xml:XML = new XML();
      xml.ignoreWhite = true;
      xml.onLoad = function()
      {
      var nodes:Array = this.firstChild.childNodes;
      for(var i=0;i<sa.length;i++) {
      sa.push(nodes .attributes.url);
      }
      playSong();
      }

      xml.load("songs.xml");

      //PLay the mp3 file
      function playSong() {
      if (cps == sa.length -1) {
      cps = 0;
      s.loadSound(sa[cps], true);
      }
      else {
      s.loadSound(sa[++cps], true);
      }
      }


      NOw im using actionscript 3 ( i think) could that be the cause?

      Any help appreciated!!!
        • 1. Re: new to actionscript...call to undefined method
          MatthewFord Level 1
          Hello,

          To see if you are coding in ActionScript3 (which is the default in CS3), check your Publish settings. There you can pick AS2 or AS3.

          AS3 did in fact change many things, for the better IMO but it takes some getting used to.

          Looking at AS3 help, the Sound class does not have a method called loadSound. Maybe it did in AS2, but was obsoleted--not sure as I only dabbled in AS2. AS3 has a lot of nifty new ways to load assets.

          Since the Sound class does not have the loadSound method, you get that compile error. CS3 compiles in "strict mode" by default-- which is a good thing as it catches errors like this at compile time.

          Not a sound expert I am loath to give you the best solution for AS3 but I recommend you trawl the help for the Sound class. In particular you can look at help for Sound.load().