Welcome, guest Sign In

ASTRA AudioPlayback

AudioPlayback is a UI component that creates a set of controls for audio playback.

Getting Started: AudioPlayback for Flash CS3

Similar to other Flash components, you can create an AudioPlayback component by placing an instance on the stage or by using ActionScript to create an instance dynamically.

Initializing a AudioPlayback component on the Stage

The easiest way to create an AudioPlayback component is to drag it from the Components panel to the stage. This will immediately create an AudioPlayback instance and add it to the display list. You will need to use actionscript to set its width and load the media file.

Note: In order for the AudioPlayback component to display the artist and title of your mp3, your mp3 file will need to either be in hosted in the same domain as the AudioPlayback component's SWF or be hosted in a domain that contains a crossdomain.xml file that allows the domain of the AudioPlayback component's SWF.

Screen capture of AudioPlayback

To see a live example, please install Adobe Flash Player version 9 or higher.

Download the FLA file.

Let's create an application that contains an AudioPlayback component and a form field to allow the user to type in a url for the audio file. First, we will drag the following components to the stage.

  • TextInput with an instance name of urlInput
  • Button with an instance name of loadUrl
  • AudioPlayback with an instance name of audioPlayback

Next, we'll use actionscript to set the width of the audio player and attach a function that will load audio when the user clicks the button.

audioPlayback.width = this.stage.stageWidth;
loadButton.addEventListener(MouseEvent.CLICK, loadMedia);

function loadMedia(event:MouseEvent):void
{
	audioPlayback.loadMedia(urlInput.text, false);
}
		

Initializing an AudioPlayback component with ActionScript

To include an AudioPlayback component in your application with ActionScript, you must first add the AudioPlayback component to your library. You can do so by dragging it from the Components panel directly to the library, or by dragging an instance to the stage, and immediately removing it (it will stay in your library). Additionally, you need to import the following class for use in your class or frame script.

import com.yahoo.astra.fl.controls.AudioPlayback;
import fl.controls.Button;
import fl.controls.TextInput;
		

Instantiate each component and add the function to load the audio.

var audioPlayback = new AudioPlayback(this);
audioPlayback.width = this.stage.stageWidth;

var urlInput:TextInput = new TextInput();
urlInput.width = 310;
urlInput.height = 22;
urlInput.x = 5;
urlInput.y = 44;
addChild(urlInput);

var urlButton:Button = new Button();
urlButton.width = 60;
urlButton.height = 22;
urlButton.x = 332;
urlButton.y = 44;
urlButton.label = "Load Url";
urlButton.addEventListener(MouseEvent.CLICK, loadMedia);
addChild(urlButton);

function loadMedia(event:MouseEvent):void
{
	audioPlayback.loadMedia(urlInput.text, false);
}
		

Download the FLA file.

For additional topics, please read Using AudioPlayback, or take a look at the Examples section for functional demonstrations. The ActionScript 3.0 Class Reference contains full details on every property, method, and style available to the AudioPlayback component.

YDN LIBRARIES & BEST PRACTICES

YAHOO! APIs & WEB SERVICES

LANGUAGE CENTERS

Copyright © 2008 Yahoo! Inc. All rights reserved. Copyright | Privacy Policy

Help us continue to improve the Yahoo! Developer Network - Send Your Suggestions