Javascript/flash onClick Issues

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved

Join Date: May 2009
Posts: 10
Reputation: MattTheHat is an unknown quantity at this point 
Solved Threads: 0
MattTheHat MattTheHat is offline Offline
Newbie Poster

Javascript/flash onClick Issues

 
0
  #1
May 25th, 2009
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:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function setPageAS()
  2. {
  3. //This variable obtains the length of the relevant XML array
  4. gPageISlength = (gXML.getElementsByTagName(gPageIS).length);
  5.  
  6. //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.
  7. for ( var i = 0; i <= (gPageISlength - 1); i++ )
  8. {
  9. gBoxIdent = ("gBox" + (i + 1));
  10. tempPhrase = (document.getElementById("gboxLAYER").innerHTML);
  11.  
  12. document.getElementById("gboxLAYER").innerHTML =
  13. (tempPhrase) +
  14. ("<div id='") +
  15. (gBoxIdent) +
  16. //this is where i would put the onClick event but it just won't call it when the content is flash.
  17. ("' class='gBoxCLASS'></div>");
  18.  
  19. //this bit gets the contents of the XML tag and puts it in a variable
  20. gBoxLOC = (gXML.getElementsByTagName(gPageIS)[i].childNodes[0].nodeValue);
  21.  
  22. //adds the content using the gBoxLOC variable to locate the flash file in question.
  23. document.getElementById(gBoxIdent).innerHTML =
  24. ("<object type='application/x-shockwave-flash' allowScriptAccess='never' allowNetworking='internal' height='300'width='300' top='0' left='0' align='left' data='") +
  25. (gBoxLOC) +
  26. ("' ><param name='allowScriptAccess' value='never' /><param name='allowNetworking' value='internal' /><param name='movie' value='")+
  27. (gBoxLOC) +
  28. ("' /></object>");
  29. }
  30. }

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.
Last edited by MattTheHat; May 25th, 2009 at 8:29 am.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 862
Reputation: Airshow is on a distinguished road 
Solved Threads: 122
Airshow's Avatar
Airshow Airshow is offline Offline
Practically a Posting Shark

Re: Javascript/flash onClick Issues

 
0
  #2
May 25th, 2009
Matt,

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.

Airshow
Last edited by Airshow; May 25th, 2009 at 8:56 am.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 10
Reputation: MattTheHat is an unknown quantity at this point 
Solved Threads: 0
MattTheHat MattTheHat is offline Offline
Newbie Poster

Re: Javascript/flash onClick Issues

 
0
  #3
May 25th, 2009
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!
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 862
Reputation: Airshow is on a distinguished road 
Solved Threads: 122
Airshow's Avatar
Airshow Airshow is offline Offline
Practically a Posting Shark

Re: Javascript/flash onClick Issues

 
0
  #4
May 25th, 2009
M.T.H.,

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).

Airshow
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 10
Reputation: MattTheHat is an unknown quantity at this point 
Solved Threads: 0
MattTheHat MattTheHat is offline Offline
Newbie Poster

Re: Javascript/flash onClick Issues

 
0
  #5
May 25th, 2009
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
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC