4 Replies Latest reply on Dec 10, 2006 12:01 PM by SerpicoLugNut

    calling Javascript inside Flash w/ getURL

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

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

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

      Thanks
        • 1. Re: calling Javascript inside Flash w/ getURL
          HitParader Level 1
          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.
          • 2. Re: calling Javascript inside Flash w/ getURL
            SerpicoLugNut Level 1
            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.
            • 3. Re: calling Javascript inside Flash w/ getURL
              HitParader Level 1
              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.

              • 4. Re: calling Javascript inside Flash w/ getURL
                SerpicoLugNut Level 1
                Hmmm. That didn't work, but I got it working using another approach.

                First, I ditched the previous js and used the Dreamweaver show/hide beavior. The code Dreameaver produces for the link looks like this:
                <!-- code : < a href="javascript:" onclick="MM_showHideLayers('layername',' ', 'show')">Link</a> -->
                Converted to the getURL function, it looks like this:
                getURL("javascript:MM_showHideLayers('layername', ' ', 'show')");

                I found a reference to it doing a google search, and a site came up that referenced it in French. Hopefully, this solution will rank higher for those looking for a solution in English. :-)