Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Firefox Thinks My Function "is not a function."

Posted on 2011-02-11
11
Medium Priority
?
1,111 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

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…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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.
Suggested Courses

636 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