Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2006-04-03
11
Medium Priority
?
291 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!
0
Comment
Question by:blue44
  • 5
  • 4
  • 2
11 Comments
 
LVL 17

Expert Comment

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

BR Dushan
0
 
LVL 16

Expert Comment

by:sam85281
ID: 16367019
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
 
LVL 16

Expert Comment

by:sam85281
ID: 16367028
Sorry, I totally read that wrong...was thinking that was a javascript function above.

-Sam
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Expert Comment

by:sam85281
ID: 16367091
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
 

Author Comment

by:blue44
ID: 16376129
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
 
LVL 16

Expert Comment

by:sam85281
ID: 16376757
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
 
LVL 17

Expert Comment

by:Dushan De Silva
ID: 16377463
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
 

Author Comment

by:blue44
ID: 16378042
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
 

Author Comment

by:blue44
ID: 16378056
Dushan,

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

Many thanks,
blue44
0
 
LVL 16

Accepted Solution

by:
sam85281 earned 1200 total points
ID: 16378233
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
 

Author Comment

by:blue44
ID: 16378480
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
The goal of the tutorial is to teach the user how to how to record live broadcast.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.
Suggested Courses
Course of the Month11 days, 18 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question