开发者

I had a problem with javascript alert fuunction

开发者 https://www.devze.com 2023-03-29 15:11 出处:网络
I am having 3 kind of swf players and if any one of player is playing all others should pause. 1 st one - audioPlayer - autoplay = true;

I am having 3 kind of swf players and if any one of player is playing all others should pause.

1 st one - audioPlayer - autoplay = true; 2 nd one - audioPlayer - autoplay = false; 3 rd one - audioPlayer - autoplay 开发者_开发百科= false;

If 2nd and 3rd paused or ended then 1st one should continue if it was not paused.

This is my java script code.

function videoPlaying(val){
    tmp = val;
}    
function sendTojs(value){
        if(value == "end" || value == "pause"){
         thisMovie("movie0").sndToAS("pause");
         alert("done");
    }
    for(i=0; i<=7; i++){
         var mov="movie"+i;
        if(tmp!=mov){
                thisMovie(mov).sndToAS("resume");
            }
         }
        }

here sndToAS is my actionscript function and tmp will have the strings "resume", "pause" and "end". I have used externalInterface.callBack in AS3.

actionscript3.0

within callback function

if(val == "pause")
{
    videoPlay();
}

My problem: if I use the alert function within sendTojs then the condition is working else not. Why?


If adding an alert fixes the problem, then it's a timing problem. The alert stops execution until you dismiss it, radically changing the timing of the code. Perhaps there's an asynchronous operation that needs to complete?


Perhaps you have a situation where the display is not being updated until the script pauses (in this case for an alert). Try using setTimeout().

if(tmp2=="end")
 {
    thisMovie("movie0").sndToAS("pause"),
    setTimeout(function() {},1);
 } 


you said

I have used externalInterface.call in AS3

its not externalInterface.call its ExternalInterface.addCallback

ExternalInterface.addCallback( "sndToAS", myJsCallBack );
function myJsCallBack ( val:String ):void{
  switch( val ){ // do your validation in ActionScript
    case "pause":
      // do pause toggle here
      break;
    case "end":
      // do stop here
      break;
    case "start":
      // do start here
      break;
  }
}

In javaScript you need this

thisMovie("movie0").sndToAS(tmp);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号