php_novice2007 Posted August 17, 2007 Share Posted August 17, 2007 Hi, I've got the following function: function animatePath(ppoly) { if (d>=eol) { alert("6"); killAni(); alert("7"); return; } alert("5"); var p = ppoly.GetPointAtDistance(d); var indexNum = ppoly.GetIndexAtDistance(d); aniIndexCount++; if( paused == 0 ) { d = d + step; alert("here1"); setTimeout("animatePath(ppoly)", tick); } alert("8"); carMarker.setPoint(p); alert("9"); map.addOverlay(carMarker); alert("10"); } The variables d, eol, step, tick, carMarker, and map are all global. When I run this function, I get the alert boxes 5, here1, 8,9,10, and then an error saying ppoly is undefined. I'm guessing its within the setTimeout function, when the timer expires, the function calls itself, but somehow it doesn't recognise ppoly... How can I fix this? Please help.. thanks! Quote Link to comment Share on other sites More sharing options...
gurroa Posted August 17, 2007 Share Posted August 17, 2007 And what is ppoly? Object? Than you can't use setTimeout syntax as you did. Because in fact it than call somethink like animatePath([object]). If ppoly is stored in some global array or it is an element of the document use setTimeout('animatePath(document.getElementById("'+ppoly.id+'")', tick); or setTimeout('animatePath(getPoly(ppoly.id))', tick); where getPoly is function that retrieve ppoly object. Quote Link to comment Share on other sites More sharing options...
php_novice2007 Posted August 17, 2007 Author Share Posted August 17, 2007 ppoly is a javascript object.. its actually a polyline object from google maps. Since the object is not defined by me, does it have an id..? Quote Link to comment Share on other sites More sharing options...
gurroa Posted August 17, 2007 Share Posted August 17, 2007 You have to call setTimeout in the same way you've called animatePath for the first time. Considering that setTimeout will call it's function from the global scope. Maybe if you post bigger part of your script... Quote Link to comment Share on other sites More sharing options...
php_novice2007 Posted August 17, 2007 Author Share Posted August 17, 2007 Sure.. The code that calls animatePath for the first time is this: function startAnimation(){ aniIndexCount = 0; var radiocounter; for (radiocounter = 0; radiocounter < animation_form.AnimationChoice.length; radiocounter++) { if (animation_form.AnimationChoice[radiocounter].checked) { break; } } var tmpPoly; for (var i=0; i<polyArray.length; i++) { tmpPoly = polyArray[i]; if (tmpPoly.myname == animation_form.AnimationChoice[radiocounter].value) { alert("1"); eol = tmpPoly.Distance(); //total distance of the polyline. alert("2"); paused = 0; d = 0; step = eol/300; //so the animation will run for 30 seconds since time step is 100 ms. carMarker = new GMarker(tmpPoly.getVertex(0),gicon["car"]); break; } } animatePath(tmpPoly); } Basically when the user clicks on a button to start the animation, it finds out which path the user has chosen by the radio buttons. And then picks out the path from an array, and set it to the path in which animatePath will follow through... Maybe it would work if I make ppoly a global variable and just have startAnimation() set the path chosen to be ppoly and then aimatePath won't need an input parameter.. But the thing is, I want to eventually make the program so that I could be animating multiple paths at the same time, so instead of having radio buttons have check boxes and when the user clicks start animation goes through all the check boxes figure out which paths needs to be animated and save them all in an array and pass it to animatePath which can go through each path and step through them.. For now I'm just trying to get one working Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.