> , Flash > Flash AS 3.0 XML MP3-

Flash AS 3.0 XML MP3-


29 2011, 15:35. : Mysterious Master
AS 3.0 XML MP3- , ActionScript ( ). 3- , , .

, Flash CS3, 4 5, ActionScript 3.0. , , . -prev_btn- , pause_btn-, - next_btn-. ActionScript Class main. , .

  Flash AS 3.0 XML MP3-



package
{
import flash.display.Sprite;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.Event;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.events.MouseEvent;
import flash.display.Loader;

import gs.TweenMax;
import gs.easing.*;

public class main extends Sprite
{
private var sound:Sound = new Sound();
private var sc:SoundChannel = new SoundChannel();
private var currentSound:Sound = sound;
private var currentIndex:Number = 0;

private var xml:XML;
private var musicList:XMLList = new XMLList();
private var musicReq:URLRequest;
private var imgReq:URLRequest;
private var isPlaying:Boolean = true;

private var loader:Loader = new Loader();

private var pos:Number

public function main():void
{//construnctor
super();

loadXML("main.xml");
settings();
option();
}

protected function loadXML(nameXML:String):void
{
var URLReq:URLRequest = new URLRequest(nameXML);
var URLLoad:URLLoader = new URLLoader(URLReq);

URLLoad.addEventListener(Event.COMPLETE, whenLoaded)
}

protected function whenLoaded(e:Event):void
{
xml = new XML(e.target.data);
musicList = xml.song;
musicReq = new URLRequest(musicList[0].url);
sound.load(musicReq);
sc = sound.play();
isPlaying = true;

imgReq = new URLRequest(musicList[0].img);
loader.load(imgReq);
album.addChild(loader);
loader.x = 0
loader.y = 0;
loader.alpha = 0;
loader.scaleX = loader.scaleY = .485;
TweenMax.to(loader ,4,{autoAlpha:1});

}

protected function settings():void
{
with(pause_btn)
{
addEventListener(MouseEvent.CLICK, pauseMusic);
}

with(next_btn)
{
addEventListener(MouseEvent.CLICK, nextMusic);
}

with(prev_btn)
{
addEventListener(MouseEvent.CLICK, prevMusic);
}
}

protected function pauseMusic(e:MouseEvent):void
{
pos = sc.position;
sc.stop();
isPlaying = false;
}

protected function nextMusic(e:MouseEvent):void
{
trace("next");

if (currentIndex0)
{
currentIndex--;
}
else
{
currentIndex = musicList.length() - 1;
}

var nextReq:URLRequest = new URLRequest(musicList[currentIndex].url);
var prevSong:Sound = new Sound(nextReq);

sc.stop();
sc = prevSong.play();
isPlaying = true;
currentSound = prevSong;

sc.addEventListener(Event.SOUND_COMPLETE, nextMusic);

var nextImg:URLRequest = new URLRequest(musicList[currentIndex].img);
loader.load(nextImg);
album.addChild(loader);
loader.x = 0
loader.y = 0;
loader.alpha = 0;
loader.scaleX = loader.scaleY = .485;
TweenMax.to(loader ,4,{autoAlpha:1});
}

protected function option():void
{
pause_btn.buttonMode = true;
next_btn.buttonMode = true;
prev_btn.buttonMode = true;
}
}
}

XML Mp3- . !