Skip to main content
Participating Frequently
December 9, 2006
Question

calling Javascript inside Flash w/ getURL

  • December 9, 2006
  • 1 reply
  • 275 views
Hello -
I'm trying to execute a javascript command inside the getURL command inside of Flash.
The javascript command looks like this in the HTML:

<a href="javascript://"
onclick="swapLayers('layer'); return false">Layer</a>



When I try to convert this to the getURL property like this:
getURL("javascript:onclick=swapLayers('layer'); return
false");
...
I get a Syntax error. Does anybody have an idea on how to properly format the this js inside the getURL command?

Thanks
This topic has been closed for replies.

1 reply

Participant
December 9, 2006
have you tried just:

getURL("javascript:swapLayers('layer')");

Assuming there is a function within the HTML page named swapLayers.

If you are publishing as Flash 8 and it does not work, try publishing as Flash 7 or earlier.
Participating Frequently
December 10, 2006
I have a Flash file of a map broken down by county. When the user clicks on a county, I need to load a hidden div with that county's zip codes in it. I'm using a javascript that activates/deactivates the layer using a javascript trigger. Here's the javascript code:

var cur_lyr; // holds id of currently visible layer
function swapLayers(id) {
if (cur_lyr) hideLayer(cur_lyr);
showLayer(id);
cur_lyr = id;
}

function showLayer(id) {
var lyr = getElemRefs(id);
if (lyr && lyr.css) lyr.css.visibility = "visible";
}

function hideLayer(id) {
var lyr = getElemRefs(id);
if (lyr && lyr.css) lyr.css.visibility = "hidden";
}

function getElemRefs(id) {
var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
if (el) el.css = (el.style)? el.style: el;
return el;

And here's the trigger:

<!-- code goes here - <a href="javascript://" onclick="swapLayers('layer'); return false">layer</a> -->

I tried to use the syntax you supplied and it didn't work.

I know the js code works, because the HTML link above triggers the layer on the page. But it's not working inside Flash with the getURL command. I've also tried outputting as Flash 7 and didn't have any success either.
Participant
December 10, 2006
I see, yes in that earlier example I thought you wanted to pass the text string "layer" to the jScript function.

So I believe here you just need to pass the correct parameter in your function call, like this: (this example assumes you want to pass the number 10 as the layer you want to show)

var layerNumber = 10;
var linkString = "javascript:swapLayers(" + layerNumber + ")"
getURL (linkString);

I would imagine you have some kind of routine in the Flash peice that calculates what the layer number you want to show is, so you just need to insert that variable into your javascript URL using a method like the above.