We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

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

blue44
blue44 asked
on
Medium Priority
309 Views
Last Modified: 2008-01-09
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!
Comment
Watch Question

Dushan De SilvaTechnology Architect

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

BR Dushan

Commented:
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

Commented:
Sorry, I totally read that wrong...was thinking that was a javascript function above.

-Sam

Commented:
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

Author

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.

Commented:
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
Dushan De SilvaTechnology Architect

Commented:
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.

Author

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

Author

Commented:
Dushan,

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

Many thanks,
blue44
Commented:
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

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
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.