p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning ActionScript 2.0 (http://p2p.wrox.com/forumdisplay.php?f=256)
-   -   Javascript call inside of getURL (http://p2p.wrox.com/showthread.php?t=51345)

serpicolugnut December 9th, 2006 04:42 PM

Javascript call inside of getURL
 
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>
When I try to convert this to the getURL property like this:
Code:

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


jberg December 15th, 2006 04:39 PM

Hello,

Your attempt is spot on. However, there's a caveat to what you are attempting.

In your original JavaScript, "onclick" is an event handler defined as an attribute of the <a> tag within the document object model of the web page. So the browser does the heavy lifting for you by associating this event with that specific <a> tag.

So what we need to do is take the contents of that onclick event and apply it to a new event. In this case we want the event to be controlled by the getURL event within Flash.

In this case, as long as the Flash is on the same page as where the function swapLayers is available, we can do the following.

Code:

getURL("javascript:swapLayers('layer');");
I am not quite sure why the return false exists at the end of the statement, so I removed it. If you are afraid IE will enact upon some return value via this getURL call then you should use the following syntax to void the return.

Code:

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


serpicolugnut December 16th, 2006 12:29 PM

I scrapped the previous javascript and went with using Macromedia Dreamweavers javascript code to show/hide layers. It works fine in Firefox and Safari, but doesn't do anything in IE6, and partially works in IE7 (in IE7 it shows the layers being swapped, but it doesn't hide the layer that it replaces).

I have an example loaded in my sandbox to see the behavior:
http://www.pixegen.com/sandbox/map.html

Any ideas on why it isn't working in IE, and how I might go about fixing it?


jberg December 16th, 2006 01:24 PM

I noticed in your footer that you have the following:

<a href="javascript:" onclick="MM_showHideLayers('troup','','show')">Tro up</a>

This won't work. Try removing the href attribute, since the onclick is handling your event.

These JavaScript issues may be better answered in the JS forum at http://p2p.wrox.com/javascript-85/




serpicolugnut December 18th, 2006 09:20 PM

OK, I think I'm making *some* progress. But I've hit another issue with IE6/7 (works fine in Ff, Safari, etc.)

I have a mc that when the user clicks on it toggles a checkbox in a div. When the user clicks another mc (a back button), a getURL is called to load a javascript to swap back to another div, and then another getURL is called to uncheck all the checkboxes. It works as expected in every browser other than IE. It seems IE is only executing one of the getURLs. Is this a known limitation of IE, or have I hit upon another error?

I have all my files viewable (and downloadable) at http://pixegen.com/jstest/ . I am using Flash 8, but exporting my swf in Flash 7 format.

The button that triggers the getURLs that aren't working fully is the back button on each of the alpha, beta and gamma frames. I've tried swapping the order, but that just means one loads and the other doesn't. Any ideas?



All times are GMT -4. The time now is 08:44 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.