ExternalInterface.call(resetPlay); needs to be
ExternalInterface.call("resetPlay");
(the param is a String)
See more here:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/external/ExternalInterface.html#call()
A
On Tue, Nov 29, 2011 at 5:19 PM, Arknath <[email protected]> wrote:
> Thanks for the quick response! I think I've made some progress as to
> what I'm doing here...learning as I go. :)
>
> 1) From what it seems, the code is not designed to take the mp3
> variable initially. With some slight changes to my own code, I've got
> this calling the doPlay and stopPlay functions appropriately. (I'll
> post new code below)
>
> 2) This was my fault. I thought I needed to destroy the SWF and
> recreate it every time. Silly me...I have since fixed that (as you'll
> soon see)
>
> 3) I did look at this more closely and this is something I was hoping
> for from the resetPlay function. When the music stops (i.e. when
> stopPlay has successfully executed) I want the JS to know that so that
> I can reset a style to the original state (basically change a "stop"
> button back to a "play" button). I thought the resetPlay callback was
> going to do that for me, no such luck.
>
> I have this working exactly the way I want except for that last issue
> of the JS knowing when the song has stopped playing. Thanks for the
> help, as your suggestions were correct. One more piece and I think i
> have this thing licked. :)
>
>
> On Nov 29, 4:03 pm, Aran Rhee <[email protected]> wrote:
> > A couple of things which stand out:
> >
> > 1) I don't see anywhere in your pasted Flash code which deals with a
> Flash
> > var called "mp3", so I am unsure if there is more to the code or if the
> swf
> > is not designed to take the mp3 var initially...
> >
> > 2) As you have a proper ExternalInterface method which loads / kills
> > external sounds etc, you shouldn't ever need to destroy/recreate your swf
> > (unless you are using the same dom element to load other swfs/content.
> >
> > 3) I would listen for the "resetPlay" function call in your html/js code,
> > as this tells you when the swf is loaded/external interface is all set up
> > etc. You are then safe to call doPlay(), stopPlay() etc on your swf.
> >
> > 4) Have a look at the EI example o the test suite to see how the code
> > checks for the existence of functions / wires up the html buttons etc:
> >
> > http://www.bobbyvandersluis.com/swfobject/testsuite_2_2/test_dynamic_...
> >
> > with embed callback:
> http://www.bobbyvandersluis.com/swfobject/testsuite_2_2/test_dynamic_...
> >
> > Cheers,
> > Aran
> >
> >
> >
> >
> >
> >
> >
> > On Tue, Nov 29, 2011 at 2:59 PM, Arknath <[email protected]> wrote:
> > > Hi all,
> >
> > > New to the group, so hi!
> >
> > > Having an issue getting my JS to call ActionScript (AS) functions.
> >
> > > Scenario:
> >
> > > Have a page full of ringtones (15-25) and want to have the ability to
> > > play a preview before purchase. Using a single file (ringtone.swf)
> > > that has ActionScript that looks like this (I did not write this AS):
> >
> > > import flash.external.*;
> >
> > > ExternalInterface.addCallback("stopPlay", this, stopPlay);
> > > ExternalInterface.addCallback("doPlay", this, doPlay);
> >
> > > _global.mySong = null;
> > > _global.duration = null;
> > > _global.position = null;
> > > _global.playingID = null;
> > > _global.streamingID = null;
> > > _global.absoluteURL = "/url/where/ringtone/stored/ringtone.php?id=";
> >
> > > function formatTime(millis) {
> > > var mins = Math.floor(millis / 60000);
> > > var remaining = millis - (mins * 60000);
> > > var secs = Math.floor(remaining / 1000);
> > > if(secs < 10){
> > > secs = '0' + secs;
> > > }
> > > return mins + ':' + secs;
> > > }
> >
> > > var tooLong = 0;
> >
> > > function displayStreaming(mySound, where) {
> > > if(tooLong++ > 3000) {
> > > ExternalInterface.call('alert', "We're sorry, it appears
> that
> > > this ringtone isn't available for listening at this time. Please try
> > > again later.");
> > > clearInterval(streamingID);
> > > stopPlay();
> > > tooLong = 0;
> > > } else if(mySound.duration > 0) {
> > > if(mySound.getBytesLoaded() == mySound.getBytesTotal())
> {
> > > clearInterval(streamingID);
> > > ExternalInterface.call(isLoaded);
> > > tooLong = 0;
> > > }
> > > where.text = formatTime(mySound.duration);
> > > }
> > > }
> >
> > > function displayPosition(mySound, where) {
> > > if(mySound.position > 0){
> > > if(mySound.position == mySound.duration) {
> > > clearInterval(playingID);
> > > }
> > > where.text = formatTime(mySound.position);
> > > }
> > > }
> >
> > > function doPlay(mp3){
> > > theSong = loc + absoluteURL + mp3;
> >
> > > clearInterval(streamingID);
> > > clearInterval(playingID);
> >
> > > if(typeof mySong == "object") {
> > > mySong.stop();
> > > delete mySong;
> > > }
> >
> > > duration.text = '0:00';
> > > position.text = '0:00';
> >
> > > mySong = new Sound();
> > > mySong.loadSound(theSong, true);
> >
> > > streamingID = setInterval(displayStreaming, 1, mySong, duration);
> > > playingID = setInterval(displayPosition, 1, mySong, position);
> >
> > > mySong.onSoundComplete = function(){ stopPlay(); }
> > > }
> >
> > > function stopPlay() {
> > > duration.text = "0:00";
> > > position.text = "0:00";
> >
> > > mySong.stop();
> > > delete mySong;
> >
> > > clearInterval(streamingID);
> > > clearInterval(playingID);
> >
> > > ExternalInterface.call(resetPlay);
> > > }
> >
> > > function initSound() {
> > > duration = _root.total_txt;
> > > position = _root.time_txt;
> > > }
> >
> > > initSound();
> >
> > > My JS looks like this:
> >
> > > //Embeded <object> ID
> > > var embed_id = "ringtone";
> >
> > > //Global SWFObject vars
> > > var player = "myContent";
> > > var audio_file = "/assets/swf/ringtone.swf";
> > > var player_width = '16';
> > > var player_height = '16';
> > > var flash_ver = "9.0.0";
> > > var express_install = false;
> > > var params = {allowScriptAccess: "always", swliveconnect: "true",
> > > wmode: "transparent"};
> > > var attributes = {id:embed_id,name:embed_id};
> > > var call_backs = function(){};
> >
> > > //Gets current site URL
> > > var base_url = "http://" + window.location.hostname + "/
> > > product/";
> >
> > > function loadSWF(preview_id){
> >
> > > //SWFObject Vars
> > > var flashvars = {loc: base_url};//, mp3: preview_id};
> > > //var flashvars = {};
> >
> > > swfobject.embedSWF(audio_file, player, player_width,
> player_height,
> > > flash_ver, express_install, flashvars, params, attributes,
> > > call_backs);
> > > }
> >
> > > //Determines the existence or absence of a previously embedded swf
> > > file
> > > function swfExists(obj_id){
> > > var exists = false;
> > > var object_tag = $("#"+obj_id);
> >
> > > if(object_tag && (object_tag.is("object") ||
> > > object_tag.is("embed"))){
> > > exists = true;
> > > }
> > > console.log("Exists: " +exists);
> > > return exists;
> > > }
> >
> > > $(document).ready(function(){
> >
> > > $(".ringtone-preview").on("click",function(e){
> > > e.preventDefault();
> > > var preview_id = $(this).attr('id');
> > > console.log("Preview ID:" + preview_id);
> > > //check to see if object exists
> > > if(swfExists(embed_id)){
> > > console.log("Secondary click");
> > > swfobject.removeSWF(embed_id);
> > > $("body").append("<div id='"+player+"'></div>");
> > > loadSWF(preview_id);
> > > }else{
> > > console.log("Primary click");
> > > loadSWF(preview_id);
> > > }
> >
> > > var obj = document.getElementById(embed_id);
> > > console.log(obj);
> > > if (obj){
> > > obj.doPlay(preview_id);
> > > console.log("Playing");
> > > }
> > > });
> > > });
> >
> > > I get an error when it gets to the "obj.doPlay(preview_id)" line that
> > > reads:
> >
> > > obj.doPlay is not a function
> >
> > > If run loadSWF without the "mp3 : preview_id" piece commented out,
> > > then it plays the ringtone. However, I want to be able to access the
> > > stopPlay() function if the user fires the .ringtone-preview event
> > > again.
> >
> > > I feel i'm almost there...just need access to the flash script.
> >
> > > Any help is appreciated.
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "SWFObject" group.
> > > To post to this group, send email to [email protected].
> > > To unsubscribe from this group, send email to
> > > [email protected].
> > > For more options, visit this group at
> > >http://groups.google.com/group/swfobject?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "SWFObject" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/swfobject?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"SWFObject" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/swfobject?hl=en.