Chapter 31 Example 4

by actionscriptbible
♥0 | Line 33 | Modified 2010-02-05 05:43:31 | MIT License
play

ActionScript3 source code

/**
 * Copyright actionscriptbible ( http://wonderfl.net/user/actionscriptbible )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/rMat
 */

package {
  import flash.display.Sprite;
  import flash.events.Event;
  import flash.media.*;
  import flash.net.URLRequest;
  import flash.text.*;

  public class ch31ex4 extends Sprite {
    protected var sound:Sound;
    protected var channel:SoundChannel;
    protected var songInfoTF:TextField;

    public function ch31ex4() {
      createChildren();
      var songurl:String = "http://actionscriptbible.com/files/winter.mp3";
      sound = new Sound(new URLRequest(songurl),
                        new SoundLoaderContext(1000, true));
      sound.addEventListener(Event.ID3, onMetadata);
      channel = sound.play();
    }
    protected function createChildren():void {
      var txtFormat:TextFormat = new TextFormat("_typewriter", 14, 0);
      songInfoTF = new TextField();
      songInfoTF.defaultTextFormat = txtFormat;
      songInfoTF.autoSize = TextFieldAutoSize.LEFT;
      addChild(songInfoTF);
    }
    protected function onMetadata(event:Event):void {
      songInfoTF.text = "NOW PLAYING:\n" + 
                        sound.id3.songName + "\n" + 
                        "from " + sound.id3.album + "\n" +
                        "by " + sound.id3.artist; 
    }
  }
}