Solved

Firefox Thinks My Function "is not a function."

Posted on 2011-02-11
11
1,072 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
 
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how can display objects ? 3 23
JS Plugin Chaining 2 32
alert before form submission 6 30
Apply tab index in forms 6 33
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

910 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now