Witam,

Próbuję osadzić pewną funkcję JS w PHP.

sam kod JS:

Kod
window.onload = podmiana;
var thisAd = 0;
var Ad = 255;
var dodaje = 0.25;
var czas = 1 / dodaje;
function podmiana(){
thisAd++;

if(thisAd == Ad){
thisAd = 0;
}

setTimeout("podmiana()", 1000*czas);

}


Nie muszę chyba tłumaczyć jak działa

A oto ten kod wsadzony w PHP tylko, że zmienna thisAd w imagestring:

  1. <?
  2. (...)
  3. $im = imagecreatefrompng("tablice/".$img);
  4. $textcolor = imagecolorallocate($im, 255, 255, 255); // kolor biały
  5. $textcolor2 = imagecolorallocate($im, 0, 255, 0); // kolor zielony
  6.  
  7. print "<script type='text/javascript'><!--\n";
  8. print "window.onload = podmiana;\n";
  9. print "var thisAd = 0;\n";
  10. print "var Ad = 255;\n";
  11. print "var dodaje = 0.25;\n";
  12. print "var czas = 1 / dodaje;\n";
  13. print "function podmiana(){\n";
  14. print "thisAd++;\n";
  15. print "if(thisAd == Ad){\n";
  16. print "thisAd = 0;\n";
  17. print "}\n";
  18. //print "document.getElementById('zmiana').innerHTML = thisAd;\n";
  19. print "imagestring($im, 2, 20, 106, thisAd, $textcolor2);";
  20. print "setTimeout('podmiana()', 1000*czas);\n";
  21. print "}\n";
  22. print "//--></script>\n";
  23. /////Wyświetlanie hp
  24. //imagestring($im, 2, 20, 106, "", $textcolor2);
  25. //// KONIEC wyświetlanie hp
  26. /////Wyświetlanie mana
  27. imagestring($im, 2, 20, 120, $_GET['mana']."/".$_GET['mana'], $textcolor);
  28.  
  29. //// KONIEC wyświetlanie mana
  30. header('Content-type: image/png');
  31.  
  32. imagepng($im);
  33. imagedestroy($im);
  34.  
  35. ?>


Wszystko wydaje się być OK ale nie działa ;-?

czy funkcja timeout potrafi/da radę współpracować z imagestring?
// prosze nie zwracać uwagi na zakomentowane linijki, bo skrypt jest w postaci roboczej.