Solved

Firefox Thinks My Function "is not a function."

Posted on 2011-02-11
11
1,078 Views
Last Modified: 2012-05-11
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?
0
Comment
Question by:caf210
  • 6
  • 4
11 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 34873329
0
 

Author Comment

by:caf210
ID: 34873451
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
 

Accepted Solution

by:
caf210 earned 0 total points
ID: 34873867
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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 29

Expert Comment

by:Badotz
ID: 34878092
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
 

Author Comment

by:caf210
ID: 34888056
<<< 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
 
LVL 29

Expert Comment

by:Badotz
ID: 34888139
>>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
 

Author Comment

by:caf210
ID: 34888296
<<< 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
 
LVL 29

Expert Comment

by:Badotz
ID: 34888739
>><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
 

Author Comment

by:caf210
ID: 34888964
Thanks for all your advice! I will heed these suggestions going forward.
0
 
LVL 29

Expert Comment

by:Badotz
ID: 34889249
Just remember: free advice is usually worth what you pay for it ;-)

No worries - glad to help.
0
 

Author Closing Comment

by:caf210
ID: 34904830
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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question