11 Replies Latest reply on Sep 18, 2007 9:18 AM by TheShade001

    help with externalInterface class


      i am working on a page for an educational environment. It is a foreign language page that teaches the students the language. There are close to 100 different playable sounds on the page. The person that set it up for them, initially, just converted over 100 mp3's to swf's and embedded them all into an HTML page. The result is BRUTAL. It takes forever to load the page and even once it is loaded it puts such a demand on the browser that you cannot scroll (browser's scrollbar) properly. It lags for 5 seconds or so everytime you want to scroll.

      I was wanting to use 1 swf container on the page that was NOT visible (hidden) and pass it a varialbe everytime a link was clicked (i would create a button that would be reused for all the different sounds). I think this will help solve this issue for them. I saw someone using flashvars to do this on another page, but I wasn't sure how to set up my SWF to receive them.

      i need to do something similar to what is in the code below, however, i don't want it to autoplay. It would need to pass the mp3 to flash upon clicking an HTML button. I am not sure how to pull this off. I want to be able to click the HTML button and tell flash to play a different mp3.

      i would appreciate any help on this. It is a HUGE problem that they have called me about to see if i can help remedy it. I am extremely desperate to get some help. I have never used this class before so i dont know how to setup the flash file, javascript or HTML. Yikes. For what it is worth, i am very comfortable with Action Script and use it often for complex scenerios. I have just never used AS to communicate with Javascript in this way before.

      thank you sooooo much for any help!

        • 1. Re: help with externalInterface class
          TheShade001 Level 1
          can anyone point me in the right direction? I am really in a bind. I appreciate any input.

          thank you so much!
          • 2. Re: help with externalInterface class
            Well, ExternalInterface is certainly the approach that I would take with this. I'm not professional, though, so be sure to get ideas from a variety of sources. In brief: you want to expose ActionScript functions so that they are callable from the web browser via JavaScript, right? Check out the ExternalInterface.addCallback function.

            There are a number of pretty good examples in the Flash 8 help system; work through those. After you're comfortable there, then make, break, and repair your own experiments. Then, get your movie to the point where you can use JavaScript to play a single audio file. Finally, extend your movie to as many audio clips as you need.

            A caveat: it's probably going to take some time to load all of the audio clips; you'll have to find some way to account for when the user presses a button and nothing happens. One solution is to use a visible movie with a preloader, and to just do everything from there. How firm is the requirement to not have a visible movie?

            Bob Robertson
            • 3. help with externalInterface class
              TheShade001 Level 1
              thanks a million, bob. I appreciate your helpful reply. I have tried going through some of the help files and have gotten a fair understanding of the addCallback function. I was having an EXTREMELY difficult time, however, applying it to what i need it for. I am not sure how to set up the FLA to playback the audio files.

              I wasn't sure if i needed to setup an MP3 player (which i have no problem doing) or if i could just use an empty swf container with AS. You mentioned that i may have to load all the audio clips in flash? Is this how you pull something like this off? I didn't know if i could just point, in html, to a directory with the mp3's and use flash as sort of a media object to play them.

              this guy is doing, pretty much, exactly what i need to do...except i need it to be audio instead of video. http://www.scotflash.co.uk/test%20player/index.html
              if you click the 3, left thumbs on top of the movie, it will change the content. When i viewed the source...this is what i was trying to do. In HTML he is just referencing different file names and passing them to the flash movie.

              To answer your question, it is not manditory to have the player invisible, but since i just needed a media container to play audio files i figured that would be a good way to do it. I am very ignorent with this particular setup so i really don't know the best strategy.

              thank you so much for your help and i will continue my searching. I have not had much luck, though, being that this is a fairly specific request.

              thanks again!
              • 4. Re: help with externalInterface class
                TheShade001 Level 1
                if anyone can give me further insight...please help! i am getting very desperate. Thank you sooooo much!
                • 5. Re: help with externalInterface class
                  TheShade001 Level 1
                  can anyone help me??? Or, at least, help point me in the right direction? I desperately need some help if anyone could take the time.

                  thank you soooooooo much.
                  • 6. Re: help with externalInterface class
                    TheShade001 Level 1
                    • 7. help with externalInterface class
                      Kees_Kist Level 1
                      You want some variable to be sent to Flash when you 'click on an HTML button', right?


                      <script type="text/javascript">
                      function toFlash(filename) {


                      Check every 2 seconds or so if the playThisMP3 variable is set in the root MovieClip. You can also call ActionScript methods directly from JS, which would eliminate the need to check every few seconds (which is poor practise), but I don't remember if from memory.
                      • 8. Re: help with externalInterface class
                        Greg Dove Level 4
                        You use the
                        (as Bob mentioned earlier) to register local functions for javascript function calls.

                        That eliminates the need for the repeated checking mentioned above.
                        • 9. help with externalInterface class
                          TheShade001 Level 1
                          thank you for your relpies. So i do not need to do anything in the flash file (as far as an mp3 player)? I can just use AS correct? I am going to experiment now. So, in theory, i could use the javascript function above and the ExternalInterface class (addCallback) to pull off what i am trying to do?

                          thank you guys so very much. I am really in a bind. I know this can be done fairly easily. I have just never done it.

                          i really, really, really appreciate it!
                          • 10. Re: help with externalInterface class
                            Greg Dove Level 4
                            That's pretty much it...You will need some actionscript to load and play the mp3 file once you know its url.

                            The function inside the swf that is called from javascript just needs to be passed the url as a parameter. Then you need to have code to handle that (load, play etc) using the Sound class (and probably cancel any existing sound that is playing first).

                            • 11. help with externalInterface class
                              TheShade001 Level 1
                              thank you sooo much man. I really appreciate it. I am going to try it now. I hate to be a pest, but if you get a chance...do you think you could help me with the AS function? I know it is a lot to ask, but i thought it wouldn't hurt to ask.

                              i guess i would use a variable for the "load" and "play," but i am not certain how to set this up. I will give it a shot at any rate.

                              thanks again, you have been EXTREMELY helpful! I can't tell you how much i appreciate it.