<?xml version="1.0" encoding="utf-8"?>
<mx:Application name="SoundEffect_useDuration_test"
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white"
initialize="init();">
<mx:Script>
<![CDATA[
import mx.containers.ApplicationControlBar;
import mx.containers.Form;
import mx.containers.FormItem;
import mx.controls.Button;
import mx.controls.CheckBox;
import mx.controls.HSlider;
import mx.effects.SoundEffect;
import mx.events.SliderEvent;
private var soundEffect:SoundEffect;
private var checkBox:CheckBox;
private var slider:HSlider;
private var btn:Button;
private function init():void {
soundEffect = new SoundEffect();
soundEffect.source = "http://www.helpexamples.com/flash/sound/song1.mp3";
checkBox = new CheckBox();
checkBox.selected = true;
checkBox.addEventListener(Event.CHANGE, checkBox_change);
slider = new HSlider();
slider.minimum = 0;
slider.maximum = 5000;
slider.value = soundEffect.duration;
slider.snapInterval = 100;
slider.tickInterval = 100;
slider.liveDragging = true;
slider.setStyle("showTrackHighlight", true);
slider.addEventListener(SliderEvent.CHANGE, slider_change);
btn = new Button();
btn.label = "Play sound effect"
btn.setStyle("mouseDownEffect", soundEffect);
btn.addEventListener(MouseEvent.MOUSE_DOWN, btn_mouseDown);
var formItem1:FormItem = new FormItem();
formItem1.label = "useDuration:";
formItem1.addChild(checkBox);
var formItem2:FormItem = new FormItem();
formItem2.label = "duration:";
formItem2.addChild(slider);
var formItem3:FormItem = new FormItem();
formItem3.addChild(btn);
var form:Form = new Form();
form.styleName = "plain";
form.addChild(formItem1);
form.addChild(formItem2);
form.addChild(formItem3);
var appControlBar:ApplicationControlBar;
appControlBar = new ApplicationControlBar();
appControlBar.dock = true;
appControlBar.addChild(form);
Application.application.addChildAt(appControlBar, 0);
}
private function checkBox_change(evt:Event):void {
soundEffect.useDuration = checkBox.selected;
slider.enabled = checkBox.selected;
}
private function slider_change(evt:SliderEvent):void {
soundEffect.duration = evt.value;
}
private function btn_mouseDown(evt:MouseEvent):void {
soundEffect.stop();
}
]]>
</mx:Script>
</mx:Application>