setTimeout in objects causes out of stack stack space

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?
BartSAsked:
Who is Participating?
 
a.marshConnect With a Mentor Commented:
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
 
a.marshCommented:
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
 
CJ_SCommented:
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
BartSAuthor Commented:
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
 
BartSAuthor Commented:
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
 
a.marshCommented:
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
 
CJ_SCommented:
sounds like my coding style

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

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

0
 
CJ_SCommented:
and in his case it is an object he has created.
0
 
a.marshCommented:
Whoops!

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

:oP

Ant
0
 
CJ_SCommented:
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
 
a.marshCommented:
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
 
a.marshCommented:
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
 
BartSAuthor Commented:
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
 
BartSAuthor Commented:
I can give you each 300 if I knew how.
0
 
a.marshCommented:
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
 
modderCommented:
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
 
a.marshCommented:
Thanks modder.

:o)

Ant
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.