Jump to content

something weird going on..


php_novice2007

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/65360-something-weird-going-on/
Share on other sites

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.

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 :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.