I'm having a problem with a quite complex piece of code, basically i cannot use an onClick event on my <div></div> element because it contains a flash file that is capturing all the clicks on it. Let me guide you through my code:
It uses an XML document to load .SWF files into layers on a PHP page using JavaScript (talk about code nightmare!). The code is the same on four pages but has to load different numbers of .SWFs depending on the page. The way it does that is by getting the number of elements referenced to the page using it's URL so the page /PGraphics.php sets the variable 'gPageIS' to PGraphics which is a corresponding tag in the XML file.
Here is the code snippet in question:

function setPageAS()
//This variable obtains the length of the relevant XML array
gPageISlength = (gXML.getElementsByTagName(gPageIS).length);

//This loop shows the correct number of layers and populates them with their corresponding .SWF; it will loop as many times as there are elements of the correct name in the XML file.
for ( var i = 0; i <= (gPageISlength - 1); i++ )
	gBoxIdent = ("gBox" + (i + 1));
	tempPhrase = (document.getElementById("gboxLAYER").innerHTML);

	document.getElementById("gboxLAYER").innerHTML =
		(tempPhrase) + 
		("<div id='") +
		(gBoxIdent) +
//this is where i would put the onClick event but it just won't call it when the content is flash.
		("' class='gBoxCLASS'></div>");
//this bit gets the contents of the XML tag and puts it in a variable
	gBoxLOC = (gXML.getElementsByTagName(gPageIS)[i].childNodes[0].nodeValue);

//adds the content using the gBoxLOC variable to locate the flash file in question.
	document.getElementById(gBoxIdent).innerHTML = 
		("<object type='application/x-shockwave-flash' allowScriptAccess='never' allowNetworking='internal' height='300'width='300' top='0' left='0' align='left' data='") +
		(gBoxLOC) + 
		("' ><param name='allowScriptAccess' value='never' /><param name='allowNetworking' value='internal' /><param name='movie' value='")+
		(gBoxLOC) + 
		("' /></object>");

gPageIS : contains the name of the page in question also is the name of the XML tags relating to that page.

note: there are 8 predefined gBox layers and never more than 8 elements of a corresponding name in the XML file.

You'll notice there is no onClick in there and that's because i can't get it to work anywhere; i've tried putting it on the layer, on the object tag itself I've even tried calling the javascript function from the flash file's actions but i have very limited understanding of actionscript 3 so this was a failure too.

The code works fine if the content of the layers is anything other than a flash file.

What i want to know is; is there a way to call a function (say makeLarge()) by clicking on the layer?
if not is there some sort of work around i can use?

I've tried to explain exactly what i'm doing here but if you have any questions please ask. Thank you all in advance.


It's about 8 years since I did anything like this so please forgive me for not recalling every detail.

I was responsible for the javascript side of things while somone else created the swf. As in your problem we had to pass through a flash-click to the js and were just about to give up when my section leader suggested using a VB script as a conduit for the function call. And it worked!!

Fortunately, the whole process is well documented, see this page for example (looks comprehensive). You will see that a vb script is conditionally written for some browser/os combinations. You will need to test thoroughly in as many browsers as possible to make sure that the conditions under which the vb is written cover the latest versions (esp IE 7 and 8).

It's moderately involved, so I reckon you will do well to solve it inside 3 days, even with the help of the guidance. It would take me longer because I would need to learn flash first.

Workaround: Put a "Larger image" HTML button or link outside the flash area.

Good luck.


Thank you very much, I'll check that out.

The other thing I'm now trying is attempting to get the flash file to call the JavaScript function. I'll see how that goes and if that fails I'll try the VBscript script approach and if that fails I will cry and then add a normal text box with an onClick event!


Just thought of another workaround.

Depends on how interactive your swf needs to be, but if it is a simple animation, then save it as an animated gif, then serve it either wrapped like this <a href="" onclick="fnCall(); return false;"><img src="myAnim.gif" ... /></a> or with an image map to define clickable area(s) and their action(s).


Yeah i thought of that but I have several alpha fades in the .SWFs and they don't work very well in .GiF format.

cheers anyway

This question has already been answered. Start a new discussion instead.