views:

91

answers:

2

Hi All,

Ideal situation/setup: A page containing 1 Flash movie and a separate div containing a few hyperlinks. These hyperlinks each have a unique class name like so: Copy code

  <ul>
  <li><a href="" class="randomname1"></a></li>
  <li><a href="" class="randomname2"></a></li>
  <li><a href="" class="randomname3"></a></li>
  <li><a href="" class="randomname4"></a></li>
  </ul>

The Flash movie itself will contain 4 buttons. Clicking on one of these buttons should make the Flash communicate with Jquery/JS and tell it to highlight the specific classname.

Ideas so far

For the javascript, it would look like

$(function() {
function setClass(className) {$("."+className).css("background","red");}
});

And in specific keyframes within Flash

   1. button 1
   ExternalInterface.call("setClass","randomname1");

   1. button 2
   ExternalInterface.call("setClass","randomname2");

   1. button 3
   ExternalInterface.call("setClass","randomname3");

   1. button 4
   ExternalInterface.call("setClass","randomname4");

The problem is that it is not really working well and i am not sure if i am making Flash communicate with JS properly.

Any ideas or hints to steer me in the right direction again? Thank you in advance

J.

A: 

Have you tested for ExternalInterface availability with ExternalInterface.available ?

elias
A: 

The setClass method will not be visible to the flash code - as the method is encapsulated inside the $(document).ready() closure

(In case you are wondering, your $(function()... call is simply shorthand to $(document).ready(function()...)

You need to attach the method to the window object or some other globally accessible object for the flash to see it. Something like:

$(function() {
    window.setClass = function(className) {$("."+className).css("background","red");}
});

which is the simplest approach.

...or to stop window namespace pollution:

$(function() {
    var ns = window.myNamespace = {};
    ns.setClass = function(className) {$("."+className).css("background","red");}
});

....then in Flash:

ExternalInterface.call("myNamespace.setClass","randomname1");

....of note however is that I'm not familiar enough with flash to know whether the second example will work.

Graza
Thank you Graza for the explanation. I have tried the suggestions and i have a feeling that i am just not doing something correctly.I have made the base file available herehttp://www.mediafire.com/?yigmfed0migHopefully the problem is very simple :)
Jason B.
That file/site seems to be "private". You might want to change that as the link isn't working - then test it in a different browser to make sure you can access it when you're not actually logged in (in which case others will be able to see it). I'm not sure *I* could be much more help though - as mentioned, I'm not that familiar with Flash, but hopefully someone else can help you...
Graza
Hi Graza,The link should be available now - http://www.mediafire.com/?yigmfed0migIf you can take a look at the JS and html, that would be great already as i think the problem is more in the JS itself?
Jason B.
Hard to quickly interpret that javascript, as it's all on one line - would be much easier for me (or anyone else who wants to help) if it had human-readable formatting (line-breaks, tabs, etc).
Graza
You mean the html in the rar file? i have uploaded it again, this time utf-8 format (i use notepad++) http://www.mediafire.com/?2yt2m3jleux
Jason B.
I also use notepad++. swfobject.js has had basic minification done (spaces and line breaks removed). I'm not sure if this is a standard flash include file, or one that flash creates for each project? If it's standard I guess theres no need for me to look at that. Your html file javascript looks fine. Can you post up what code you have in flash (the ExternalInterface.call() code) now?
Graza
swfobject.js is standard and does not need any modifications.In Flash, i basically have a timeline with 3 keyframes set to keyframe 5, 25, 50.When pressing the buttons you goto these 3 keyframes.On the keyframe itself, i have the following code.stop();ExternalInterface.call("myNamespace.setClass","randomname1");On the other keyframes i just have the same code, just with different classname
Jason B.
"myNamespace" was just an example for the SECOND way (namespacing) I suggested of doing things - your html appears to be using the FIRST way (using window/global method). Change that call in your flash file to `ExternalInterface.call("setClass","randomname1");` and it should work.
Graza
Ah, it worked! When clicking on a button, it does highlight the classname now. Only problem is how can i make it so that it does only highlight one classname each time instead of it staying 'on' all the time? Pressing button 1 and then button 2 means that both randomname1 and randomname2 become highlighted
Jason B.
You will need to loop through all the controls each time a button is pressed and set them to "off" before setting the clicked control to "on". Alternatively, you can assign multiple classes to an element. If you add a second class to all the buttons (the same classname for each one) then you could turn them all off with a single statement, before turning the one that was clicked back on.
Graza
I don't think i have the know how into make the JS behave that it should turn off all the single statements, you can view the code here http://img88.imageshack.us/img88/6278/codetn.jpg , sorry but i had a hard time placing markdown code into this comment
Jason B.
Your `$('.menu')...` line is only being called once on document ready - you need to move it into the start of the `setClass` method so it gets called (they get set to yellow) every time your Flash calls the `setClass` method
Graza
Thank you Graza for your time and help, it all works now! =)
Jason B.
No problems - you might want to "accept" the answer as otherwise this question will remain open on Stack Overflow, causing other people to waste their time looking at it.
Graza