5
             if(tmpStr == tmp+value)
             {
                i=1;
                action = null;
                action2 = null;
             }
             if(tmpStr1 == tmp+value)
             {
                i=0;
                            action();//not working
                            action2();//not working
             }
             for(i;i<=14; i++)
             {
                 if(tmp!="movie"+i) 
                 {
                    document.getElementById("movie"+i).sndToAS("resume");
                 }
             }

         }
         function action()
         {
            document.getElementById("movie0").sndToAS("pause");
         }
         function action2()
         {
            if(tmp != "movie0")
            {
                document.getElementById("movie0").sndToAS("pause");

            }
         }
6
  • 1
    Could you elaborate please? I don't get what you're asking here Commented Aug 20, 2011 at 13:18
  • 2
    Actually I am using JS for communicationg with flash audio and video players. My code little bit larger. I wants to know is there any Listener like addEventListener and removeEventListener?. Commented Aug 20, 2011 at 13:25
  • 1
    In a simple way... how to disable and enable functions? Commented Aug 20, 2011 at 13:26
  • 1
    Downvote?????...pls put down a comment. Commented Aug 22, 2011 at 4:38
  • 1
    What is the need for elaborate??? I know how to deactivate the functions and I don't know how to reactivate the functions. This code is enough for that. Commented Aug 22, 2011 at 4:58

3 Answers 3

5

Do something like this

function actionFunc(){
    document.getElementById("movie0").sndToAS("pause");
}
function action2Func()
{
    if(tmp != "movie0"){
     document.getElementById("movie0").sndToAS("pause");

    }
}

window.action = actionFunc;
window.action2 = action2Func;

if(tmpStr == tmp+value)
{
    id=1;
    window.action = null;
    window.action2 = null;
}
if(tmpStr1 == tmp+value)
{
    id=0;
    window.action = actionFunc;
    window.action2 = action2Func;
}

Then when you want to call your functions all you have to do is

action();
action2();

but your going to want to check if the are set before calling them

I believe thats what your after

or do something like this

function action(){
    if (window.actionEnabled)
    {
       document.getElementById("movie0").sndToAS("pause");
    }
}
function action2()
{
    if (window.action2Enabled)
    {
       if(tmp != "movie0"){
         document.getElementById("movie0").sndToAS("pause");
       }
    }
}

window.actionEnabled = true;
window.action2Enabled = true;

if(tmpStr == tmp+value)
{
    id=1;
    window.actionEnabled = false;
    window.action2Enabled = false;
}
if(tmpStr1 == tmp+value)
{
    id=0;
    window.actionEnabled = true;
    window.action2Enabled = true;
}

then you don't have to check if the are enabled just call them and they will work or want depending on if they are enabled

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

Comments

1

If you don't want a function to execute when in a particular state, I would wrap your function do a state check and then a return if in an inappropriate state.

function action(obj){
   if(obj.state == <a state you dont want to execute>)
     return;

   action();
} 

function action(){
   document.getElementById("movie0").sndToAS("pause");
}

Comments

0

just declare a global variable

var stopfunction=false;

and as a first line in your function

if (stopfunction) return;

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.