[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Cant use setInterval function properly in actionscript....

Posted on 2006-05-03
3
Medium Priority
?
275 Views
Last Modified: 2006-11-18
Hi,
This is one function in my action script. I am calling this function on my buttons "release" event.
================================
on (release) {
go1();

var intervalId:Number;
function go1(){
trace("Hello!!!");
intervalId = setInterval(go2(),3000)
clearInterval(intervalId);
}

function go2(){
intervalId = setInterval(go1(),3000);
clearInterval(intervalId);
}
}
================================

I guess In above function when user clicks on button it should trace mesage "Hello!!!" in the interval of 6000 miliseconds. But its not happening here.
When I am clicking on button at that time only once I am getting followin output with error message:-
================================
Hello!!!
Hello!!!
Hello!!!
Hello!!!
256 levels of recursion were exceeded in one action list.
This is probably an infinite loop.
Further execution of actions has been disabled in this movie.
================================

Why I am getting this error? & What should i do to get the above output message in interval of 6000 miliseconds.
Please help me.
Thanx in advance.
Prash
0
Comment
Question by:Econify
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
wings_gaurav earned 1500 total points
ID: 16603627
on (release)
{
var intervalId:Number;
function go1()
{
      trace("Hello!!!");
      clearInterval(intervalId);
}

intervalId = setInterval(go1,6000)
}

should work fine.

The problem is with
intervalId = setInterval(go1(),3000); // go1() should be just go1 without brackets
when you say this - you are calling go1 not passing function name as reference.



- wings
0
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 16603725
Hi gaurav,

your code will only show the "Hello!!!" once and that even after 6000 milliseconds of clicking..


here I have fine-tune the code, it will show the "Hello!!!" as user clicks and then after every 6000 milliseconds.
----------------
on (release) {
      var intervalId:Number;
      if (intervalId != undefined) {
            clearInterval(intervalId);
      }
      function go1() {
            trace("Hello!!!");
      }
      go1();
      intervalId = setInterval(go1, 6000);
}
---------------

Rgds
Aneesh
0
 
LVL 5

Expert Comment

by:wings_gaurav
ID: 16603742
Mr. Aneesh,

It would be advisable if you read the requirnments posted by the user before providing your expert comments.

Best Regards,
Gaurav
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question