0
你好,我需要在我的flash文件上顯示一個圖像,這是一個音樂播放器,以便我可以放置音樂計分表。玩家從一個XML文件中獲取歌曲,這裏是我的ActionScript代碼:如何使用xml文件和AS3將圖像,歌曲和藝術家名稱添加到Flash播放器?
var my_songs:XMLList;
var my_total:Number;
var my_sound:Sound;
var my_channel:SoundChannel;
var current_song:Number = 0;
var song_position:Number;
var song_paused:Boolean;
var myXMLLoader:URLLoader = new URLLoader();
myXMLLoader.load(new URLRequest("playlist.xml"));
myXMLLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void {
var myXML:XML = new XML(e.target.data);
my_songs = myXML.SONG;
my_total = my_songs.length();
//playSong(0);
myXMLLoader.removeEventListener(Event.COMPLETE, processXML);
myXMLLoader = null;
}
function playSong(mySong:Number):void {
var myTitle = my_songs[mySong][email protected];
var myArtist = my_songs[mySong][email protected];
var myURL = my_songs[mySong][email protected];
var myImageURL = my_songs[mySong][email protected];
var url:URLRequest = new URLRequest(myImageURL);
var img:Loader = new Loader();
img.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded);
img.load(url);
function loaded(event:Event):void
{
event.target.removeEventListener(Event.COMPLETE, loaded);
var bitmap:Bitmap = event.target.content;
addChild(bitmap);
}
title_txt.text = myTitle;
artist_txt.text = myArtist;
if (my_channel) {
my_channel.stop();
my_channel.removeEventListener(Event.SOUND_COMPLETE, onNext);
}
my_sound = new Sound();
my_sound.load(new URLRequest(myURL));
my_channel = my_sound.play();
my_channel.addEventListener(Event.SOUND_COMPLETE, onNext);
}
next_btn.addEventListener(MouseEvent.CLICK, onNext);
function onNext(e:Event):void {
current_song++;
if (current_song>=my_total) {
current_song=0;
}
playSong(current_song);
}
prev_btn.addEventListener(MouseEvent.CLICK, onPrev);
function onPrev(e:MouseEvent):void {
current_song--;
if (current_song<0) {
current_song = my_total-1;
}
playSong(current_song);
}
pause_btn.addEventListener(MouseEvent.CLICK, onPause);
function onPause(e:MouseEvent):void {
if (my_channel) {
song_position = my_channel.position;
my_channel.stop();
song_paused=true;
}
}
play_btn.addEventListener(MouseEvent.CLICK, onPlay);
function onPlay(e:MouseEvent):void {
if (song_paused) {
my_channel = my_sound.play(song_position);
song_paused=false;
} else if (!my_channel) {
playSong(current_song);
}
}
menu_home.addEventListener(MouseEvent.CLICK, fl_ClickToGoToWebPage);
function fl_ClickToGoToWebPage(event:MouseEvent):void
{
navigateToURL(new URLRequest("http://www.portugal.gov.pt"), "_blank");
}
fs_btn.addEventListener(MouseEvent.CLICK, fullScreen);
function fullScreen(event:MouseEvent):void {
stage.displayState=StageDisplayState.FULL_SCREEN;
}
import fl.events.SliderEvent;
import flash.media.SoundTransform;
var voltransform:SoundTransform = new SoundTransform();
sc.addEventListener(SliderEvent.THUMB_DRAG,changevol);
function changevol(event:SliderEvent):void{
voltransform.volume=sc.value;
SoundMixer.soundTransform=voltransform;
}
和XML如下:
是的,我需要添加圖像,因爲兒子g名字和藝術家名字已經在每首歌曲上顯示txs for answear艱難我需要每首歌曲中的不同圖像你知道我該怎麼做? – 2015-04-07 01:29:40
你可以把你的playSong函數中的代碼?當歌曲開始時它會加載圖像。 – Nemi 2015-04-07 09:21:53
更新了帖子上的代碼強硬它does not工作,但肯定缺少的東西 – 2015-04-07 16:57:08