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.

Known Participant
June 6, 2011

There are several ways to decode url query variables but, perhaps, the most straightforward one is to use URLVariables class that is created for that.

For instance, say your ExternalInterface call returns the following url:

"http://www.mydomain.com/folder/page.html?var1=3&completeChapters=3,4,5,3,2,6&var3=myString"

for the sake of simplicity:

var url:String = "http://www.mydomain.com/folder/page.html?var1=3&var2=3,4,5,3,2,6&var3=myString";

To extract url query you can do the following:

var urlQuery:String = url.split("?")[1];

If you trace it - it will show:

var1=3&completeChapters=3,4,5,3,2,6&var3=myString

Now, you can use this value in an instance of URLVariables:

var urlVars:URLVariables = new URLVariables(urlQuery);
// read variablein the loop
for (var prop:String in urlVars) {
     trace(prop, "=", urlVars[prop]);
}

Trace will read:

var1 = 3
completeChapters = 3,4,5,3,2,6
var3 = myString

And here is how you convert coma delimited string into Array:

var chapters:Array = urlVars.completeChapters.split(",");


That is great! I'm going to try it out with my current informaiton.

Thank you!!!!!