Firefox Thinks My Function "is not a function."

I'm using the ExternalInterface class(?) in ActionScript 3 in my Flash document. Like this:


flash.external.ExternalInterface.addCallback("sendToActionscript", callFromJavaScript);

I also have a function in there called "callFromJavaScript."

On my HTML page, which contains the .swf file, I am using some javascript. Like so:

function callToActionscript()
{
      var myFlashMovie=document.getElementById("media/insurance");
      myFlashMovie.sendToActionscript();
}


function out() //this function is just a test and not significant to my question
{
       alert("out");
}


Then, I call it like so:

  <p><a href="#" onmouseover="javascript: callToActionscript();" onmouseout="javascript:out();" >Test</a></p>


When I hover over the "Test" anchor link, it's supposed to run a function (callFromJavasScript) in my Flash. It works PERFECTLY in IE and Safari.

But it DOESN'T WORK in Firefox. Firefox keeps telling me this:

"myFlashMovie.sendToActionscript is not a function"

I've done tests to show that I'm successfully running the "callToActionscript" javascript function, and the "mouse out" works, fine. It just doesn't seem to like that one line no matter how I write it.

I know Firefox has some issues with Javascript. I've tried placing the functions in the head tag, as well as below the body tag.

Any thoughts how I can get that line to work in Firefox?
caf210Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
caf210Connect With a Mentor Author Commented:
I found my own answer:

The embed of the SWF file, written automatically by Flash, didn't give an id to the second object. Presumably because it didn't want to give two identical IDs on the page.

So I gave it a unique id, and then added this conditional to the function:

function callToActionscript()
{      
      var myFlashMovie;
      
      var browserName = navigator.userAgent;
      
      
      if (browserName.indexOf("Firefox") >= 0) {
                  
      myFlashMovie=document.getElementById("media/insuranceff");

      }
      
      else {
      myFlashMovie=document.getElementById("media/insurance");
      
      }
      
      myFlashMovie.sendToActionscript();
      
            
}

That did the trick.
0
 
leakim971PluritechnicianCommented:
0
 
caf210Author Commented:
Leakim971,

Thanks for your thoughts. This didn't work for me either. In fact, I had an object tag for the Flash already that was just like the one in the accepted solution on that other thread. I had both, like this:

<div id="flashContent">
                   <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="150" height="100" id="media/insurance" align="middle">
                        <param name="movie" value="../media/insurance.swf" />
                        <param name="quality" value="high" />
                        <param name="bgcolor" value="#ffffff" />
                        <param name="play" value="true" />
                        <param name="loop" value="true" />
                        <param name="wmode" value="window" />
                        <param name="scale" value="showall" />
                        <param name="menu" value="true" />
                        <param name="devicefont" value="false" />
                        <param name="salign" value="" />
                        <param name="allowScriptAccess" value="sameDomain" />
                        <!--[if !IE]>-->
                        <object type="application/x-shockwave-flash" data="../media/insurance.swf" width="150" height="100">
                              <param name="movie" value="../media/insurance.swf" />
                              <param name="quality" value="high" />
                              <param name="bgcolor" value="#ffffff" />
                              <param name="play" value="true" />
                              <param name="loop" value="true" />
                              <param name="wmode" value="window" />
                              <param name="scale" value="showall" />
                              <param name="menu" value="true" />
                              <param name="devicefont" value="false" />
                              <param name="salign" value="" />
                              <param name="allowScriptAccess" value="sameDomain" />
                        <!--<![endif]-->
                              <a href="http://www.adobe.com/go/getflash">
                                    <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
                              </a>
                        <!--[if !IE]>-->
                        </object>
                        <!--<![endif]-->
                  </object>
            </div>


I tried getting rid of the first object and just left the second one, which, to my eyes is consistent with the solution for the other thread. That not only didn't help in Firefox, it also made it stop working in Safari, and in IE it couldn't even place the SWF on the page.
0
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

 
BadotzCommented:
The use of the word "javascript" is unnecessary (and confusing - what else could it possibly be?):

<p><a href="#" onmouseover="javascript: callToActionscript();" onmouseout="javascript:out();" >Test</a></p>

should be:

<p><a href="#" onmouseover="callToActionscript();" onmouseout="out();" >Test</a></p>
0
 
caf210Author Commented:
<<< The use of the word "javascript" is unnecessary (and confusing - what else could it possibly be?): >>>

I don't know. I've seen code like that written both ways (with and without the "javascript:" before it). I've also seen people ask questions in forums where they didn't have it and people responded and told them to put it in.

Is there a rule for when or when you shouldn't use it? If ever? I'm all ears.
0
 
BadotzCommented:
>>Is there a rule for when or when you shouldn't use it? If ever? I'm all ears.

I have a rule: Thou shalt not use in-line CSS or JavaScript.

All of my CSS rules and JavaScript are either external or in their own style blocks. CSS and event handlers have no place within my HTML.

I have other foibles that are not germane to your question. But basically, I adhere to the "a place for everything, and everything in its place" mindset ;-).
0
 
caf210Author Commented:
<<< I have a rule: Thou shalt not use in-line CSS or JavaScript. >>>

Ah, so when people use javascript like this...

 <a href="javascript:window.close();">Close Window</a>

...it's considered inline, and they need the "javascript" label because it's in the absence of having a custom function like closeMyWindow() written elsewhere that can be simply called?

(My javascript knowledge is very cursory, as I'm sure you can tell.)

I can appreciate your "a place for everything" approach.  With my CSS, the only time I use an inline style=" " is if I need to style something that will never be used again anywhere else on the site.

Oh, and I also use the inline styles when I am planning on changing them with javascript. For example, changing style="display: none" to "display: block." But that's because I don't know how to do it otherwise.  Hmm...perhaps I could write two classes, .display_on and .display_off and use javascript to simply re-write the class?  
0
 
BadotzCommented:
>><a href="javascript:window.close();">Close Window</a>
>>
>>...it's considered inline, and they need the "javascript" label

Yes, but you do not need to stipulate "javascript:" because it cannot be anything else!

Furthermore, never, under any circumstances, use JavaScript in the HREF attribute of a link tag - it alters so many behaviors of the link as to render it unusable:

1. You cannot drag the link to another window to open it
2. You cannot copy the link location
3. etc.

Use a handler for the "click" event instead. A bit more work (don't be a lazy coder), but in the end, your users will thanks you.
0
 
caf210Author Commented:
Thanks for all your advice! I will heed these suggestions going forward.
0
 
BadotzCommented:
Just remember: free advice is usually worth what you pay for it ;-)

No worries - glad to help.
0
 
caf210Author Commented:
I'm accepting my own solution because, simply put, I realized what the problem was before others did.

Much as I'd like to award points to someone, as busy designers and developers, I felt it was more important that no one spends extra time troubleshooting a solution I already found.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.