Jump to content


mp3Loader urlRequest as flashvars

Recommended Posts

Hi is there way to make the urlRequest in mp3Loader pull from a flashVar in .html?


We are not sure of the final directory that will store the sound samples and would like this to be a variable inside the .html


For Example, This works


var myMp3Request:URLRequest = new URLRequest("sfx/sample1.mp3");
var sample1Sound:MP3Loader = new MP3Loader(myMp3Request,{autoPlay:false,volume:.8,repeat:0});


But trying to convert the URLRequest into flashVars does not


var mySoundRequest:URLRequest = new URLRequest(root.loaderInfo.parameters.someVariable);
var sample2Sound:MP3Loader = new MP3Loader(mySoundRequest,{autoPlay:false,volume:.8,repeat:0});


Thanks for any advice!

  • Like 1
Link to comment
Share on other sites

What is the output if you trace your variable just before creating the URLRequest?

trace(root.loaderInfo.parameters.someVariable); // expecting "sfx/sample1.mp3"

If the first example is working then it is certainly a case of your someVariable being either undefined, not the correct string, or inaccessible.


Check that root.loaderinfo is definitely returning the loaderInfo for the main SWF defined in the HTML, as child SWFs don't have the FlashVars in their loaderinfo. If you are requesting from a child SWF, you will need to go up though the parents to find the stage of the main SWF.


Pass variables to SWFs | FlashVars

  • Like 1
Link to comment
Share on other sites

Thank you for your reply. If I run the above trace statement when I publish from Flash it is "undefined".


If I upload the .swf to the sever and open the .html container and view the trace log I have setup in OSX terminal it traces out the flashVars "sfx/sample1.mp3".


There is only one .swf using swfobject with the .html code as:


swfobject.embedSWF("myFlashMovie.swf", "flashmovie", "1252", "834", "10.1", xinstall, flashvars, params, props);

var flashvars = {
someVariable: "sfx/sample1.mp3"


So since it's null upon publish in Flash it won't work. Looks like it's not an issue with mp3Loader as it can accept a variable as in the first example. I'm not sure if there is a work around though, thanks.

Link to comment
Share on other sites

Maybe set a default value so you can still run it when you test the swf?

var mp3url = "sfx/sample1.mp3"; // testing default
if (root.loaderInfo.parameters.someVariable) {
   mp3url = root.loaderInfo.parameters.someVariable;
var myMp3Request:URLRequest = new URLRequest(mp3url);

  • Like 1
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.