0

I know there have been tons of questions about this topic already but none of them have solved my issue, perhaps I am just missing something.

Anyways, here is the deal. I have a happy little html5 game that plays some audio and sound affects etc and it works great in every browser that supports html5. However, those that don't require a flash fallback. No big deal right? Apparently not… I've made a small swf that should accept the mp3 url from JS and then get the mp3 and play it. I have to use this way as there are a lot of audio files and I would like to try and avoid making a swf file for each one.

Here is the AS - I'm using the ExternalInterface to receive the variable from js.

 import flash.external.*;

 ExternalInterface.addCallback("callFlash", playSound); 

 function playSound(file:String):void {
    var s:Sound = new Sound();
    s.load(new URLRequest(file));

    s.play();
 }

And then my JS to pass the variable:

 var flash = $('#fbplayer')[0];
 console.log(flash); //returns flash object so jquery is not the issue
 flash.callFlash(fallSource);

So theoretically everything should work fine (if I understand ExternalInterface correctly). However, the following error is thrown:

 TypeError: flash.callFlash is not a function
 flash.callFlash(fallSource);

I can't seem to find where the issue was. I'm open to any answers or even a completely different way of doing this. As long as it works as this is holding up the delivery of the project :C

Thanks!

MeanMatt
  • 1,545
  • 3
  • 12
  • 23
  • Is there more than 1 flash object on the page? I ask b/c of this: `var flash = $('#fbplayer')[0];` – Sunil D. Aug 10 '12 at 22:46
  • No only one flash object on the page but using [0] so that jQuery doesn't return an jQuery object - the [0] forces jQuery to take the object. As far as I know at least… – MeanMatt Aug 10 '12 at 23:27
  • The only other thing that jumps out (aside from the usual `allowScriptAccess` embed param) is that perhaps the JS is calling the Flash function before `ExternalInterface.addCallback()` has been executed. – Sunil D. Aug 11 '12 at 00:18
  • I thought of allowScriptAccess and set it to "always" which did not change anything. And I believe flash has had enough time to execute ExternalInterface as the js function that sends is linked to a click function that no matter how many times I press I still get the error. Puzzling. – MeanMatt Aug 12 '12 at 08:47
  • This is the error Chrome spits out incase it helps. `Uncaught TypeError: Object # has no method 'callFlash' main.js:20542 playMusic main.js:20542 (anonymous function) main.js:20477 f.event.dispatch jquery-1.7.2.min.js:3 f.event.add.h.handle.i ` – MeanMatt Aug 13 '12 at 16:54

1 Answers1

1

I know this is really old, but I've never had success finding my flash objects properly with jquery. It's better to go with a getElementById. Also, one other crazy thing I ran into with some modern browsers just a couple months ago is that I actually needed to tell flash to wait a frame after initializing any callbacks via ExternalInterface.

Robert Smith
  • 385
  • 4
  • 15