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!

5
  • Is there more than 1 flash object on the page? I ask b/c of this: var flash = $('#fbplayer')[0]; Commented Aug 10, 2012 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… Commented Aug 10, 2012 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. Commented Aug 11, 2012 at 0: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. Commented Aug 12, 2012 at 8:47
  • This is the error Chrome spits out incase it helps. Uncaught TypeError: Object #<HTMLObjectElement> 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 Commented Aug 13, 2012 at 16:54

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.