How to pass values from ActionScript to javascript using getURL()?

Hi,

I'm currently developing a Flex application and have an AS function that needs to pass a string of parameters to a web page.  My function looks like this:

function set source(source: String): Void {
            if (source) {
               // __source = source;
      var lat="32.56800,32.54781,32.57442,32.55789,32.55953";
      var lng=-"117.13119,-117.12292,-117.12717,-117.10606,-117.12881";
      var Names="OS,MM,TL,RC,BR"
               getURL(source, "myFrame", "GET");

}

For whatever reason, those values aren't being passed to the web page.  I'm hoping it's just a syntax issue.  Any help would be greatly appreciated!!

Thanks!
blue44Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dushan De SilvaTechnology ArchitectCommented:
You can use "?" as in normal HTML.
If you need more details, don't hesitate to contact me.

BR Dushan
0
sam85281Commented:
Well for one you can't use a space in a function name.

set source needs to be set_source

Then assuming your "source" is a web page, your AS should be in this syntax:

getURL("javascript:set_source(http://www.somePage.com);");

-Sam
0
sam85281Commented:
Sorry, I totally read that wrong...was thinking that was a javascript function above.

-Sam
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

sam85281Commented:
Use this as your AS function:

function set_source(source: String): Void {
if (source) {
var lat="32.56800,32.54781,32.57442,32.55789,32.55953";
var lng="-117.13119,-117.12292,-117.12717,-117.10606,-117.12881"; // Note you had minus sign on wrong side of quotes
var Names="OS,MM,TL,RC,BR"
getURL(source + "?lat=" + lat + "&lng=" + lng + "&Names=" + Names, "myFrame");
}

Then to retrieve them javascript put this function in the head of your source page:

<script>
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
}
}
lat = getQueryVariable(lat);
lng = getQueryVariable(lng);
Names = getQueryVariable(Names);
</script>

-Sam
0
blue44Author Commented:
Sorry for the delay in replying.  I tried the above code and get the following error.  Any ideas? Thanks!!

The reference to entity "lng" must end with the ';' delimiter.
0
sam85281Commented:
Is that a javascript or actionscript error?

Only thin I see wrong with the code (actionscript) is a missing bracket I left out, should be:

function set_source(source: String): Void {
if (source) {
var lat="32.56800,32.54781,32.57442,32.55789,32.55953";
var lng="-117.13119,-117.12292,-117.12717,-117.10606,-117.12881"; // Note you had minus sign on wrong side of quotes
var Names="OS,MM,TL,RC,BR"
getURL(source + "?lat=" + lat + "&lng=" + lng + "&Names=" + Names, "myFrame");
}
}

-Sam
0
Dushan De SilvaTechnology ArchitectCommented:
Hello,
getURL(source + "?lat=" + lat + "&lng=" + lng + "&Names=" + Names, "myFrame");

This is still using "?" to pass varible, as I suggested. Anyway blue44 this is normal way as we are using in HTML.


If you need more details, don't hesitate to contact me.

0
blue44Author Commented:
Sam,

It's an actionscript error that I'm receiving within Flex.  In Flex Builder actually, there are four errors:

- Unterminated entity reference[xml] -- Line 26
- Entity 'lng' was not found'. -- Line 26
- Unterminated entity reference[xml] -- Line 26
- Entity 'Names' was not found'.  -- Line 26

Line 26 points to the getURL call.

It doesn't make sense to me either...it seems it doesn't like appending variables to source.

Thanks!!!
Blue44
0
blue44Author Commented:
Dushan,

I'm not quite sure what you mean.  Do I not use a ? as in HTML? Please elaborate.

Many thanks,
blue44
0
sam85281Commented:
Ahhh, I know nothing about flex but lng IS a reserved xml entity.

Try changing lng and Names to longitude and myNames or something, see if that makes a difference.

Otherwise, it's got to be a problem with Flex's ability to handle dynamically built URLs.  I can't say for sure on that though.  Never used flex.

-Sam
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
blue44Author Commented:
I ended up finding the solution on a livedoc.  Here's the link:
http://livedocs.macromedia.com/flex/15/flex_docs_en/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Flex_Documentation&file=00001360.htm

The final code:

function set source(source: String): Void {
if (source) {
var formObj = new LoadVars();
formObj.lat = "32.56800,32.54781,32.57442,32.55789,32.55953";
formObj.lng = "-117.13119,-117.12292,-117.12717,-117.10606,-117.12881";
formObj.names = "OS,MM,TL,RCh,BR";
formObj.send(source, "myFrame", "POST");
}
}

Sam, because of your effort on this, I'm going to reward you the points.  Thanks again!!
blue44
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.