2

I have a music player as a SWF file and I need help converting my static AS3 source paths:

var url :URLRequest = new URLRequest("images/logo.jpg");
var req:URLRequest = new URLRequest("click.mp3");

...into parameters that can be passed in from the HTML page. I'd like to do something like this:

<object width="480" height="270" data="soundplayer.swf" sound="click.mp3" image="logo.jpg"></object>`

The end result I am looking for is to specify the sound and image path within the HTML code instead of it being hard coded within my SWF file.

3
  • You already have the HTML in your question... what are you trying to do? Commented Jun 12, 2015 at 22:20
  • Trying to use html parameters as my source instead of it being within my as3 swf file Commented Jun 12, 2015 at 23:00
  • My swf file is a player. It originally gets the background image and sound through as3. I would like to source it through html instead Commented Jun 12, 2015 at 23:01

1 Answer 1

3

You can accomplish this with FlashVars

You add a <param> node in your object tag with a name of FlashVars and the value should be url encoded querystring variables.

So your scenario, this would be the start of your object tag:

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="480" height="270">
    <param name="movie" value="soundplayer.swf" />
    <param name="FlashVars" value="sound=click.mp3&image=logo.jpg" />

Then in AS3, you access them as follows:

var flashVars:Object = LoaderInfo(this.root.loaderInfo).parameters;

var url:URLRequest = new URLRequest("images/" + flashVars.image);
var req:URLRequest = new URLRequest(flashVars.sound);
Sign up to request clarification or add additional context in comments.

4 Comments

I knew I needed flashVars, will check to see if this works
<param name=FlashVars should be <param name="flashVars"
var flasVars:Object should be var flashVars:Object
It will work without the quotes, but your right they should really be there (I was copying out of the documentation which leaves them off). If it worked, feel free to accept the answer! (green check mark by the voting buttons)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.