1 Reply Latest reply on Oct 24, 2006 10:31 AM by Newsgroup_User

    Developing Dynamic Sound Objects

    WebXperience Level 1
      I am creating dynamic Sound objects using the info returned from a

      for (var i in _root) evaluation.

      I have structured the name of the variable in the following code. How can I cast that [name] as a Sound Object then have it point to or load an mp3 on the server?: In other languages you can do this with a pointer. But as there are no pointers in ActionScript, is there a workaround?

      Attach Code

      j=0;
      for (var i in _root) {
      if (typeof (eval(i)) == "movieclip") {
      var name:String = i + "Sound"; // I want to use the contents of this "name " variable to create a new Sound Object which will be popluated from an XML attribute which contains the Sound URL
      var [name]:Sound = new Sound(); // This doesn't work
      sClip= eval(i);
      sClip.songTitle.text = songs[j++].attributes.desc; // songs is an array populated from an XML file.
      trace(sClip + " \n Next Line: " + name + sClip.songTitle.text);
      }
      }
        • 1. Re: Developing Dynamic Sound Objects
          Level 7
          WebXperience,

          > How can I cast that [name] as a Sound Object then have
          > it point to or load an mp3 on the server?

          In ActionScript 2.0, strong typing is *only* checked at compile time.
          It's just a convenience for light error checking, and is not actually
          adhered to in the bytecode. So in this case, you can skip it.

          > var [name]:Sound = new Sound(); // This doesn't work

          The closest I got was this ...

          this[name] = new Sound();

          ... which neither answers your question nore adheres to recommended best
          practice, but what you're after is somehow "outside the box," so to speak.
          ;)


          David Stiller
          Adobe Community Expert
          Dev blog, http://www.quip.net/blog/
          "Luck is the residue of good design."