Skip to main content
Known Participant
June 6, 2011
Question

Passing dynamic variable from html to Flash

  • June 6, 2011
  • 1 reply
  • 1983 views

I know this is pretty simple but all that I have read doesn't make much sense to me. I have one swf calling another swf that I have embedded into an htnl. In other words just calling another html page in a seperate window.

In one.swf (runing in broswer) I use the below to call another html page passing the variable NewLessonArray. This contains an array of completed chapters.

// LOADING URL
var NewLessonCompleteArray:String = LessonCompleteArray.toString();
navigateToURL(new URLRequest("two/index.html?CurrentLessonInfo=<NewLessonCompleteArray>"), "_blank");

In the receiving swf I want to retrieve the passing parameters.

two.swf

// Getting the parameters passed

this.loaderInfo.parameters.toString()

All that is returned that I can see is object Object. But since I am passing on a address line into another swf embedded in a html page I am unable to determine that correct syntac for retrieving the information.

Any suggestions? This has got to be pretty simple... I think.

THANKS

This topic has been closed for replies.

1 reply

Inspiring
June 6, 2011

Try:

ExternalInterface.call(“window.location.href.toString”);

in the swf that is in the second window.

Known Participant
June 6, 2011

ok but that return my entire string to the location of the html page. What I am looking to do is return the value passed through the html. Here is my objective...

I have a variable in one.swf... called NewLessonCompleteArray, an string. I want to use the contents of this variable to pass along a link to the calling html that contains another swf, two.swf.

var NewLessonCompleteArray:String = LessonCompleteArray.toString();

navigateToURL(new URLRequest("two/index.html?CurrentLessonInfo=<NewLessonCompleteArray>"), "_blank");

Not sure if I even have the line set up right.

In two.swf I want to retrieve the value I stored on the pass. Using your line I retrieve the entire command line. I think there is a simpler way using loaderInfo.parameters. But I can't find any information that helps in getting the information into another variable.

Ned Murphy
Legend
June 6, 2011

What you are trying to do is not extremely difficult to do, but it is not something I would consider as being simple.  With Andrei's approach you should be able to take the url String and dissect the parameters from it using String methods, like split().

As for the loaderInfo end of things, you are not passing the parameters to the swf file, you are passing them to the html page.  So the loaderInfo won't have any info for you regarding the url parameters.  The loadInfo would typically get parameters via the FlashVars parameters passed in in the html's swf embedding code.

Here are some other solutions that you might consider.  I have not dealt with these myself, they are merely in my collection of useful info, so you might have to experiment to get them working.  One is a link to a class-based approach and the other is an approach that use swfObject embedding to dynamically add the parameters as FlashVars to the embedding code....

http://mikethenderson.com/2009/02/as3-return-query-string-value-version-2/#more-105

OR

In your HTML:

 
var flashvars = {};
if (swfobject.getQueryParamValue("aParameter")) {
  flashvars.param = swfobject.getQueryParamValue("aParameter"); 
}
swfobject.embedSWF("myMovie.swf", "myContent", "550", "400", "9.0.0", "", flashvars);


And the param variable will be available as a FlashVar to your movie:

var theParam = loaderInfo.parameters.param;