Jump to content
Search Community

Mp3 Loader with Combobox and XML

vlambeat test
Moderator Tag

Recommended Posts

Hello, I am new to Greensock classes, and I am very happy with it. Please be patient with me.

 

I am adding an mp3 player to a flash website, I am trying to do it very easy,

with a combobox selector in order to choos from 5 or 6 music styles (I don't need the

information of the artist, nor the song title etc.) and just on/off toggle button and probably

a volume slider. very minimal; I want to use an XML file to reference all my mp3 files and

I want to use mp3Loader. I chose the combobox so when I change to a different music style,

the music fades out and the new one fades in.

 

With the code I have written so far, I have named the music style options in the combobox

and the combobox format, and I am usin mp3loader to load an external mp3, and a sound_mc

movieclip to toggle the sound on/off with a hit button area.

 

Any help?

 

import com.greensock.*;

import com.greensock.loading.*;

import com.greensock.events.LoaderEvent;

import com.greensock.plugins.*;

 

//Inicicalize ComboBox

stop();

 

combo.addItem( { label: "Ambient "} );

combo.addItem( { label: "Experimental "} );

combo.addItem( { label: "Relax "} );

 

var myFormat:TextFormat=new TextFormat()

myFormat.size=12;

myFormat.color=0xFFFFFF

 

combo.textField.setStyle("textFormat",myFormat)

combo.dropdown.setRendererStyle("textFormat",myFormat)

 

/////////////////////////////////////////////////////////////////

 

TweenPlugin.activate([VolumePlugin]);

 

import flash.events.MouseEvent;

 

sound_mc.alpha = 0;

 

var sound:MP3Loader = new MP3Loader("audio/Relax.mp3", {onComplete:init, volume:0, autoPlay:true, repeat:-1});

 

sound.load();

 

var soundOn:Boolean = false;

 

//wait for the sound to load

function init(e:LoaderEvent):void

{

TweenLite.to(sound_mc, .5, {alpha:1});

hit_sound_btn.addEventListener(MouseEvent.CLICK, toggleSound);

}

 

function toggleSound(e:MouseEvent):void

{

//switcheroo

soundOn = ! soundOn;

 

var myValue:int = int(soundOn) // converts true to 1, false to 0

 

TweenLite.to(sound, 1.5, {volume:myValue});

 

sound_mc.gotoAndStop(myValue + 1); // frame numbers start at 1

 

}

Link to comment
Share on other sites

if you want a seamless cross-fade effect, you might want to use a LoaderMax containing multiple MP3Loaders to pre-load all the songs, then its just a matter of telling the requested loader to playSound() (and tween the volume) and tell the current loader to fade out.

 

so you need to keep track of the current mp3 that is playing and configure your combobox to fire a CHANGE event that will handle the song switching.

 

you could use the selected label of the combobox to find the proper MP3Loader in your LoaderMax and then tell it to play. something like:

 

myLoaderMax.getLoader(whateverTheLabelIsThatWasJustSelected).playSound()

 

From your code it looks like you have only added a comboBox to my tutorial (which is great) but you should probably get some of the bare bones functionality in there for triggering an action when the user selects something new from the comboBox. maybe just start by dynamically creating a single MP3Loader based on the selected item.

 

Keep us posted on your progress.

 

-carl

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...