Solved

Firefox Thinks My Function "is not a function."

Posted on 2011-02-11
11
1,068 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
Comment Utility
0
 

Author Comment

by:caf210
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
<<< 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 29

Expert Comment

by:Badotz
Comment Utility
>>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
Comment Utility
<<< 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
Comment Utility
>><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
Comment Utility
Thanks for all your advice! I will heed these suggestions going forward.
0
 
LVL 29

Expert Comment

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

No worries - glad to help.
0
 

Author Closing Comment

by:caf210
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article discusses how to create an extensible mechanism for linked drop downs.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

743 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

18 Experts available now in Live!

Get 1:1 Help Now