Solved

setTimeout in objects causes out of stack stack space

Posted on 2001-07-15
17
602 Views
Last Modified: 2008-03-10
I'm trying to add setTimeout in a function as a method to all objects created dynamically from DIVs in the document.
This is to be able to set the setTimeout to each DIV separateley. But function Timer is executed repeatedly without waiting 1000mseconds as specified by setTimeout and causes Out of stack stack space message. The functions look like:

function myobjs(obj) {
this.objTimer = Timer;

//other methods here
}

function Timer() {
this.objSetLeft(-20);
setTimeout(objs['Layer6'].oTimer(), 1000);//Out of stack stack space
}

Any ides how to fix this?
0
Comment
Question by:BartS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 4
  • 4
  • +1
17 Comments
 
LVL 15

Expert Comment

by:a.marsh
ID: 6283575
I'm not fully clear on what you are actually trying to do....but I suspect we need to see all of your code.

Just in case, have you tried:

setTimeout("objs['Layer6'].oTimer()", 1000);


Ant
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 6283988
The quotes will fix it. This way a new timer will be created right away which will result in out of stack spaace (thousands of timers...whoopie) :-)

Regards,
CJ
0
 

Author Comment

by:BartS
ID: 6284378
Ant,

Your line fixes the stack error.

function Timer() {
this.objSetLeft(-20);
setTimeout("objs['Layer6'].oTimer()", 1000);
}
So, the above functions well. But I'm limited to hard coding Layer6.
I need to send different objects ( DIV id's) to Timer(). Therefore, the line:
setTimeout("objs['Layer6'].oTimer()", 1000);
needs to be changed to something like:
setTimeout("objs['this'].oTimer()", 1000);
so that it takes the self object as an argument.
This last line causes: Error 'obj.this' is null or not a not an object.

I also tried:
setTimeout("objs['"+this+"'].oTimer()", 1000);
setTimeout("objs["+this+"].oTimer()", 1000);
but no success.

Thanks you both
Bart
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 15

Accepted Solution

by:
a.marsh earned 150 total points
ID: 6284992
Try:

setTimeout("objs['" + this.name + "'].oTimer()", 1000);


If name doesn't work then try id instead - it will depend on your HTML....

:o)

Ant
0
 

Author Comment

by:BartS
ID: 6288211
Hi,

setTimeout is still not working, but it seems to be very close to a solution.
Here is the whole code:

<HTML><HEAD>
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">



<SCRIPT LANGUAGE="JavaScript1.2" TYPE="text/javascript">
<!--
function aobjs(obj) {
     this.css2 = obj;
     this.oSetLeft = SetLeft;
     this.oGetLeft = GetLeft;
     this.oTimer = Timer;
}

function SetLeft(left) {
     this.css2.style.left = left + "px";
}
function GetLeft() {
    var lt = parseInt(this.css2.style.left);
     return lt;
}

function makeObj() {
     var allTags = document.all.tags("DIV");
     objs = new Array();
     objs[allTags[0].id] = new aobjs(allTags[0])
     objs[allTags[1].id] = new aobjs(allTags[1]);
}

function Timer(obj) {
//alert( this.id )
this.oSetLeft(this.oGetLeft()+ 60);//merge
setTimeout("objs['" + this.id + "'].oTimer()", 1000);

//objs['Layer6'].oTimer()
//setTimeout(objs['Layer6'].oTimer(), 1000);//Out of stack stack space
//setTimeout("objs["+this+"].oTimer()", 1000);
}
//-->
</SCRIPT>
</HEAD>


<BODY BGCOLOR="#FFFFFF" style="margin:0px" onload="makeObj()">
<a href="#" onmouseover="objs['Layer1'].oTimer();">TEST</a>

  <div id="Layer1" style="position:absolute; z-index:2; left: 50px; top: 208px"><a HREF="javascript:OpenWin(1);"><img src="thumb/Dsc00178.jpg" name="Img1" width="100" height="72" border="0"></a></div>

  <div id="Layer2" style="position:absolute; z-index:4; left: 70px; top: 108px"><a HREF="javascript:OpenWin(2);"><img src="thumb/Dsc00179.jpg" name="Img2" width="100" height="72" BORDER=0></a></div>

</BODY></HTML>
0
 
LVL 15

Expert Comment

by:a.marsh
ID: 6290128
I can't really have a good look at this until I get home - but what is an "aobjs"? I've never heard of such a thing.......

What exactly is the error you are now getting?

Ant
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 6290145
sounds like my coding style

a -> active
obj -> object
s -> style

It kind of means the current active object's style. :-)

0
 
LVL 22

Expert Comment

by:CJ_S
ID: 6290146
and in his case it is an object he has created.
0
 
LVL 15

Expert Comment

by:a.marsh
ID: 6290150
Whoops!

I didn't see the function for aobjs......!

:oP

Ant
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 6290161
I don't know what you are trying to achieve, but try:

    function aobjs(obj)
    {
       this.css2 = obj;
       this.id = obj.id
       this.oSetLeft = SetLeft;
       this.oGetLeft = GetLeft;
       this.oTimer = Timer;
    }

Regards,
CJ
0
 
LVL 15

Expert Comment

by:a.marsh
ID: 6290164
The only thing I can think of simply by looking at the code is that the objs array is not in scope - tell us what the error is you're getting and we can go from there.

Ant
0
 
LVL 15

Expert Comment

by:a.marsh
ID: 6291314
CJ is correct you need to add the line:

this.id = obj.id;


Seeing as we both helped you in this question I recommend that you split the points between us.

To do that you will need to post a 0 point question in Community Support to get a moderator reduce the points on this question for you.

Once they have done that then you will be able to accept an answer.

:o)

Ant
0
 

Author Comment

by:BartS
ID: 6291644
IT's a miracle!
It works. And it makes sense.

How am I going to split the points between you now?
Thanks a lot.

Bart

N.B.
C.J. What I'm trying to achieve is to set the setTimeout to each DIV separateley. So that I can animate any DIV separately, independently. Is there a better way?

Actually, now I noticed there is a disadvantage of the above code:
If the object receives more then one mouseover, this will creat more than one instance of setTimeout of the same object. And this may not be desired.

The name "aobjs" does not ahve much meaning I created a few versions of this function for testing, so I had to make each of it distinct.

Ant, you say there is no need for this function. Is there a way to add methods to the objects without it?


0
 

Author Comment

by:BartS
ID: 6291656
I can give you each 300 if I knew how.
0
 
LVL 15

Expert Comment

by:a.marsh
ID: 6292745
Well if you're happy to give that many points away then the way to do that is to accept one of our comments as an answer on this question and then post a new question in the Javascript area with a subject of (for example):

Points for a.marsh

and in the question body, mention that the points are for help on this question.

However don't feel that you have to give away all those points - you can ask community support to reduce the points on this question to 150 and then post a new question for 150 points as above.

It's up to you - what would you prefer to do?

:o)

Ant
0
 
LVL 3

Expert Comment

by:modder
ID: 6301245
Hi BartS,

I've reduced the points from 300 to 150.

You can now award this question to one of the two experts, and, as a.marsh says in the above comment, post another dummy question for 150 points titled "Points for <the other expert>" in which you mention "for your help with http://www.experts-exchange.com/jsp/qShow.jsp?ta=javascript&qid=20150939"

Cheers

modder
Community Support Moderator@Experts-Exchange
0
 
LVL 15

Expert Comment

by:a.marsh
ID: 6301449
Thanks modder.

:o)

Ant
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

695 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