==== Code from: ActionScript 3.0 Cookbook: ID-I_0596526954_CHP_15_SECT_16_1.txt =====
package {
import flash.display.Sprite;
import flash.display.Stage;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.text.TextField;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundTransform;
import flash.net.URLRequest;
import flash.text.TextFormat;
import flash.utils.Timer;
public class CookBookPlayer extends Sprite {
private var _channel:SoundChannel;
private var _displayText:TextField;
private var _sound:Sound;
private var _panControl:PanControl;
private var _playing:Boolean = false;
private var _playPauseButton:Sprite;
private var _position:int = 0;
private var _spectrumGraph:SpectrumGraph;
private var _volumeControl:VolumeControl;
public function CookBookPlayer(()) {
// Stage alignment
stage.scaleMode =
flash.display.StageScaleMode.NO_SCALE;
stage.align = flash.display.StageAlign.TOP_LEFT;
// Enter frame listener
var timer:Timer = new Timer(20);
timer.addEventListener(TimerEvent.TIMER, onTimer);
timer.start(());
_playing = true;
// Display a text field
_displayText = new TextField(());
addChild(_displayText);
_displayText.x = 10;
_displayText.y = 17;
_displayText.width = 256;
_displayText.height = 14;
// Create a sound object
_sound = new Sound(new URLRequest(""http://www.rightactionscript.com
samplefiles/sample.mp3""));
_sound.addEventListener(Event.ID3, onID3);
_channel = _sound.play(());
// Create a bitmap for spectrum display
_spectrumGraph = new SpectrumGraph(());
_spectrumGraph.x = 10;
_spectrumGraph.y = 33;
addChild(_spectrumGraph);
// Create the Play and Pause buttons
_playPauseButton = new PlayButton(());
_playPauseButton.x = 10;
_playPauseButton.y = 68;
addChild(_playPauseButton);
_playPauseButton.addEventListener(MouseEvent.MOUSE_UP,
onPlayPause);
// Create volume and pan controls
_volumeControl = new VolumeControl(());
_volumeControl.x = 45;
_volumeControl.y = 68;
addChild(_volumeControl);
_volumeControl.addEventListener(Event.CHANGE,
onTransform);
_panControl = new PanControl(());
_panControl.x = 164;
_panControl.y = 68;
addChild(_panControl);
_panControl.addEventListener(Event.CHANGE,
onTransform);
}
public function onTransform(event:Event):void
{
// Get volume and pan data from controls
// and apply to a new SoundTransform object
_channel.soundTransform = new SoundTransform(
_volumeControl.volume,
_panControl.pan);
}
public function onPlayPause(event:MouseEvent):void
{
// If playing, stop and record that position
if(_playing) {
_position = _channel.position;
_channel.stop(());
}
else {
// Else, restart at the saved position
_channel = _sound.play(_position);
}
_playing = !_playing;
}
public function onID3(event:Event):void {
// Display selected id3 tags in the text field
_displayText.text = _sound.id3.artist + " : " +
_sound.id3.songName;
_displayText.setTextFormat(
new TextFormat("_typewriter", 8, 0));
}
public function onTimer(event:TimerEvent):void {
var barWidth:int = 256;
var barHeight:int = 5;
var loaded:int = _sound.bytesLoaded;
var total:int = _sound.bytesTotal;
var length:int = _sound.length;
var position:int = _channel.position;
// Draw a background bar
graphics.clear(());
graphics.beginFill(0xFFFFFF);
graphics.drawRect(10, 10, barWidth, barHeight);
graphics.endFill(());
if(total > 0) {
// The percent of the sound that has loaded
var percentBuffered:Number = loaded / total;
// Draw a bar that represents the percent of
// the sound that has loaded
graphics.beginFill(0xCCCCCC);
graphics.drawRect(10, 10,
barWidth * percentBuffered,
barHeight);
graphics.endFill(());
// Correct the sound length calculation
length /= percentBuffered;
// The percent of the sound that has played
var percentPlayed:Number = position / length;
// Draw a bar that represents the percent of
// the sound that has played
graphics.beginFill(0x666666);
graphics.drawRect(10, 10,
barWidth * percentPlayed,
barHeight);
graphics.endFill(());
_spectrumGraph.update(());
}
}
}
}
// "helper classes"
// (This is an outside package, but it's available to classes
// in the same file)
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.filters.DropShadowFilter;
import flash.geom.Rectangle;
import flash.media.SoundMixer;
import flash.utils.ByteArray;
class PlayButton extends Sprite {
public function PlayButton(()) {
// Draw the Play/Pause graphic
graphics.beginFill(0xcccccc);
graphics.drawRoundRect(0, 0, 20, 16, 4, 4);
graphics.endFill(());
graphics.beginFill(0x333333);
graphics.moveTo(4, 4);
graphics.lineTo(8, 8);
graphics.lineTo(4, 12);
graphics.lineTo(4, 4);
graphics.drawRect(10, 4, 2, 8);
graphics.drawRect(14, 4, 2, 8);
graphics.endFill(());
}
}
class SpectrumGraph extends Sprite {
private var _spectrumBMP:BitmapData;
public function SpectrumGraph(())
{
// Bitmap to draw spectrum data in
_spectrumBMP = new BitmapData(256, 30,
true, 0x00000000);
var bitmap:Bitmap = new Bitmap(_spectrumBMP);
bitmap.filters = [new DropShadowFilter(3, 45, 0, 1,
3, 2, .3, 3)];
addChild(bitmap);
}
public function update(()):void
{
// Get spectrum data
var spectrum:ByteArray = new ByteArray(());
SoundMixer.computeSpectrum(spectrum);
// Draw to bitmap
_spectrumBMP.fillRect(_spectrumBMP.rect, 0xff6666
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
FLASH-FLEX3.0开发教程中文版(例子源码) (207个子文件)
ID-I_0596526954_CHP_15_SECT_16_1.txt 10KB
ID-I_0596526954_CHP_6_SECT_10_3.txt 4KB
ID-I_0596526954_CHP_20_SECT_14_1.txt 4KB
ID-I_0596526954_CHP_6_SECT_10_1.txt 4KB
ID-I_0596526954_CHP_16_SECT_15_2.txt 4KB
ID-I_0596526954_CHP_6_SECT_6_3.txt 3KB
ID-I_0596526954_CHP_12_SECT_7_2.txt 3KB
ID-I_0596526954_CHP_12_SECT_13_4.txt 3KB
ID-I_0596526954_CHP_24_SECT_5_4.txt 3KB
ID-I_0596526954_CHP_13_SECT_7_15.txt 2KB
ID-I_0596526954_CHP_9_SECT_14_38.txt 2KB
ID-I_0596526954_CHP_15_SECT_10_2.txt 2KB
ID-I_0596526954_CHP_17_SECT_4_2.txt 2KB
ID-I_0596526954_CHP_9_SECT_28_2.txt 2KB
ID-I_0596526954_CHP_15_SECT_14_2.txt 2KB
ID-I_0596526954_CHP_16_SECT_13_1.txt 2KB
ID-I_0596526954_CHP_12_SECT_5_7.txt 2KB
ID-I_0596526954_CHP_19_SECT_8_1.txt 2KB
ID-I_0596526954_CHP_16_SECT_5_2.txt 2KB
ID-I_0596526954_CHP_15_SECT_11_1.txt 2KB
ID-I_0596526954_CHP_6_SECT_2_6.txt 2KB
ID-I_0596526954_CHP_1_SECT_13_3.txt 2KB
ID-I_0596526954_CHP_11_SECT_8_3.txt 2KB
ID-I_0596526954_CHP_5_SECT_4_9.txt 2KB
ID-I_0596526954_CHP_15_SECT_9_1.txt 2KB
ID-I_0596526954_CHP_6_SECT_6_1.txt 2KB
ID-I_0596526954_CHP_8_SECT_15_2.txt 2KB
ID-I_0596526954_CHP_19_SECT_4_2.txt 2KB
ID-I_0596526954_CHP_6_SECT_4_4.txt 2KB
ID-I_0596526954_CHP_9_SECT_28_1.txt 2KB
ID-I_0596526954_CHP_15_SECT_7_1.txt 1KB
ID-I_0596526954_CHP_5_SECT_11_12.txt 1KB
ID-I_0596526954_CHP_8_SECT_15_3.txt 1KB
ID-I_0596526954_CHP_19_SECT_2_3.txt 1KB
ID-I_0596526954_CHP_4_SECT_10_4.txt 1KB
ID-I_0596526954_CHP_8_SECT_9_2.txt 1KB
ID-I_0596526954_CHP_6_SECT_9_3.txt 1KB
ID-I_0596526954_CHP_24_SECT_4_15.txt 1KB
ID-I_0596526954_CHP_19_SECT_5_1.txt 1KB
ID-I_0596526954_CHP_8_SECT_14_3.txt 1KB
ID-I_0596526954_CHP_5_SECT_15_6.txt 1KB
ID-I_0596526954_CHP_15_SECT_8_2.txt 1KB
ID-I_0596526954_CHP_12_SECT_11_1.txt 1KB
ID-I_0596526954_CHP_11_SECT_8_2.txt 1KB
ID-I_0596526954_CHP_9_SECT_14_37.txt 1KB
ID-I_0596526954_CHP_6_SECT_4_1.txt 1KB
ID-I_0596526954_CHP_6_SECT_8_2.txt 1KB
ID-I_0596526954_CHP_8_SECT_8_1.txt 1KB
ID-I_0596526954_CHP_12_SECT_6_2.txt 1KB
ID-I_0596526954_CHP_6_SECT_2_5.txt 1KB
ID-I_0596526954_CHP_8_SECT_14_2.txt 1KB
ID-I_0596526954_CHP_11_SECT_6_1.txt 1KB
ID-I_0596526954_CHP_20_SECT_14_3.txt 1KB
ID-I_0596526954_CHP_6_SECT_7_2.txt 1KB
ID-I_0596526954_CHP_11_SECT_3_4.txt 1KB
ID-I_0596526954_CHP_11_SECT_4_1.txt 1KB
ID-I_0596526954_CHP_12_SECT_5_5.txt 1KB
ID-I_0596526954_CHP_7_SECT_15_1.txt 1KB
ID-I_0596526954_CHP_6_SECT_4_2.txt 1KB
ID-I_0596526954_CHP_6_SECT_8_1.txt 1KB
ID-I_0596526954_CHP_15_SECT_12_1.txt 1KB
ID-I_0596526954_CHP_19_SECT_3_5.txt 1KB
ID-I_0596526954_CHP_12_SECT_7_3.txt 1KB
ID-I_0596526954_CHP_20_SECT_12_1.txt 1KB
ID-I_0596526954_CHP_8_SECT_14_4.txt 1KB
ID-I_0596526954_CHP_11_SECT_7_7.txt 1KB
ID-I_0596526954_CHP_20_SECT_14_2.txt 1KB
ID-I_0596526954_CHP_17_SECT_7_3.txt 1KB
ID-I_0596526954_CHP_12_SECT_5_2.txt 1KB
ID-I_0596526954_CHP_8_SECT_12_8.txt 1KB
ID-I_0596526954_CHP_8_SECT_6_2.txt 1KB
ID-I_0596526954_CHP_4_SECT_8_2.txt 1KB
ID-I_0596526954_CHP_11_SECT_2_3.txt 1KB
ID-I_0596526954_CHP_19_SECT_6_1.txt 1KB
ID-I_0596526954_CHP_24_SECT_4_12.txt 1KB
ID-I_0596526954_CHP_14_SECT_9_4.txt 1014B
ID-I_0596526954_CHP_11_SECT_5_1.txt 1007B
ID-I_0596526954_CHP_5_SECT_10_2.txt 1006B
ID-I_0596526954_CHP_9_SECT_24_2.txt 1000B
ID-I_0596526954_CHP_5_SECT_10_4.txt 995B
ID-I_0596526954_CHP_6_SECT_5_1.txt 993B
ID-I_0596526954_CHP_1_SECT_13_2.txt 987B
ID-I_0596526954_CHP_6_SECT_6_4.txt 970B
ID-I_0596526954_CHP_20_SECT_14_4.txt 965B
ID-I_0596526954_CHP_9_SECT_21_2.txt 949B
ID-I_0596526954_CHP_6_SECT_3_1.txt 948B
ID-I_0596526954_CHP_4_SECT_15_6.txt 947B
ID-I_0596526954_CHP_14_SECT_2_5.txt 935B
ID-I_0596526954_CHP_12_SECT_6_5.txt 932B
ID-I_0596526954_CHP_11_SECT_7_2.txt 920B
ID-I_0596526954_CHP_4_SECT_9_1.txt 913B
ID-I_0596526954_CHP_10_SECT_6_2.txt 903B
ID-I_0596526954_CHP_8_SECT_13_2.txt 902B
ID-I_0596526954_CHP_5_SECT_12_2.txt 901B
ID-I_0596526954_CHP_6_SECT_3_2.txt 894B
ID-I_0596526954_CHP_3_SECT_6_3.txt 892B
ID-I_0596526954_CHP_5_SECT_4_1.txt 888B
ID-I_0596526954_CHP_3_SECT_5_3.txt 882B
ID-I_0596526954_CHP_14_SECT_9_3.txt 880B
ID-I_0596526954_CHP_1_SECT_18_9.txt 869B
共 207 条
- 1
- 2
- 3
wyz20020214
- 粉丝: 2
- 资源: 16
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论4