18/09/2011, 09:01
|
| | Fecha de Ingreso: mayo-2011 Ubicación: aqp
Mensajes: 52
Antigüedad: 13 años, 6 meses Puntos: 0 | |
reproducir musica en aleatorio este es el codigo fuciona bien.... sino que no randomiza osea cuando yo presione la tecla F5 no cambia de camcion..... o cambie de pagina y que escoja aleatoriamente cualquier song de mi XML gracias si me pueden ayudar
/////////////////AS3////////////////////////////////////
volume_mc.slider_mc.useHandCursor = true;
var musicReq:URLRequest;
var music:Sound = new Sound();
var sc:SoundChannel;
var currentSound:Sound = music;
var pos:Number;
var xml:XML;
var songlist:XMLList;
var currentIndex:Number = 0;
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, whenLoaded);
/////////////////////////////////////////no randomiza
function whenLoaded(e:Event):void
{
xml = new XML(e.target.data);
songlist = xml.song;
for(var j=0;j<songlist.length;j++) {
for(var i=0;i<songlist.length;i++) {
var k = Math.floor(Math.random()*songlist.length);
var t = songlist[i];
songlist[i] = songlist[k];
songlist[k] = t;
}
}
musicReq = new URLRequest(songlist[0].url);
music.load(musicReq);
sc = music.play();
title_txt.text = "Now Playing: "+ songlist[0].title;
sc.addEventListener(Event.SOUND_COMPLETE, nextSong);
}
/////////////////////////////////////////no randomiza
loader.load(new URLRequest("jukebox.xml"));
next_btn.addEventListener(MouseEvent.CLICK, nextSong);
prev_btn.addEventListener(MouseEvent.CLICK, prevSong);
pause_btn.addEventListener(MouseEvent.CLICK,pauseS ong);
play_btn.addEventListener(MouseEvent.CLICK,playSon g);
stop_btn.addEventListener(MouseEvent.CLICK,stopSon g);
function nextSong(e:Event):void
{
if (currentIndex < (songlist.length() - 1))
{
currentIndex++;
}
else
{
currentIndex = 0;
}
var nextReq:URLRequest = new URLRequest(songlist[currentIndex].url);
var nextTitle:Sound = new Sound(nextReq);
sc.stop();
title_txt.text = songlist[currentIndex].title;
artist_txt.text = songlist[currentIndex].artist;
sc = nextTitle.play();
currentSound = nextTitle;
sc.addEventListener(Event.SOUND_COMPLETE, nextSong);
}
function prevSong(e:Event):void
{
if (currentIndex > 0)
{
currentIndex--;
}
else
{
currentIndex = songlist.length() - 1;
}
var nextReq:URLRequest = new URLRequest(songlist[currentIndex].url);
var prevTitle:Sound = new Sound(nextReq);
sc.stop();
title_txt.text = songlist[currentIndex].title;
artist_txt.text = songlist[currentIndex].artist;
sc = prevTitle.play();
currentSound = prevTitle;
sc.addEventListener(Event.SOUND_COMPLETE, nextSong);
}
function pauseSong(e:Event):void
{
pos = sc.position;
sc.stop();
}
function playSong(e:Event):void
{
sc = currentSound.play(pos);
}
function stopSong(e:Event):void
{
sc.stop();
pos = 0;
}
//----VOLUME----//
var rect:Rectangle = new Rectangle(0,0,50,0);
volume_mc.slider_mc.addEventListener(MouseEvent.MO USE_DOWN,dragIt);
volume_mc.slider_mc.addEventListener(MouseEvent.MO USE_UP,dropIt);
stage.addEventListener(MouseEvent.MOUSE_UP,dropIt) ;
function dragIt(e:Event):void
{
e.target.startDrag(false,rect);
e.target.addEventListener(MouseEvent.MOUSE_MOVE, adjustVolume);
}
function dropIt(e:Event):void
{
var vol:Number = volume_mc.slider_mc.x * .02;
var st:SoundTransform = new SoundTransform(vol,0);
sc.soundTransform = st;
volume_mc.slider_mc.stopDrag();
volume_mc.slider_mc.removeEventListener(MouseEvent .MOUSE_MOVE, adjustVolume);
}
function adjustVolume(e:Event):void
{
var vol:Number = volume_mc.slider_mc.x * .02;
var st:SoundTransform = new SoundTransform(vol,0);
sc.soundTransform = st;
}
sof_mc.addEventListener(MouseEvent.CLICK, playAd);
function playAd(e:Event):void
{
ad_mc.play();
} |