Erreur "too much recursion"

cs_francois44 Messages postés 15 Date d'inscription jeudi 26 décembre 2002 Statut Membre Dernière intervention 17 novembre 2006 - 10 oct. 2006 à 09:54
cs_francois44 Messages postés 15 Date d'inscription jeudi 26 décembre 2002 Statut Membre Dernière intervention 17 novembre 2006 - 10 oct. 2006 à 10:59
Bonjour à tous

J'avance petit à petit dans la création d'un système de news en objet ...  à savoir l'adaptation de la source disponible à cette adresse : http://www.javascriptfr.com/codes/NEWS-TICKER-LETTRE-LETTRE_30623.aspx (que j'ai adapté à mon besoin).

Tout marche nickel sauf l'effet effectué par le settimeout ... ma fonction d'affichage est bel et bien appelé en récursif mais j'ai l'impression qu'il n'attent pas la fin du délai pour le faire ... ce qui me donne une erreur "too much recursion" dans firefox.

voici mon code si cela inspire quelqu'un:

merci d'avance

François


<hr />
Classe Comp_Info qui gère une seul info
<hr />/**
*Comp_Info
*Constructeur de la classe Comp_Info.
*
[mailto:*@param *@param]     string
[mailto:*@param *@param]     string
[mailto:*@param *@param]     string
[mailto:*@param *@param]     string
[mailto:*@param *@param]     string
[mailto:*@param *@param]     string
[mailto:*@param *@param]     string
*
[mailto:*@return *@return]     void
*/
function Comp_Info(str_Titre, str_Description, str_Lien, str_Date, str_Heure, str_Type, str_UrlImage)
{
 this.str_Titre = str_Titre;
 this.str_Description = str_Description;
 this.str_Lien = str_Lien;
 this.str_Date = str_Date;
 this.str_Heure = str_Heure;
 this.str_Type = str_Type;
 this.str_UrlImage = str_UrlImage;
}

/**
*get_Titre
*Retourne le titre.
*
[mailto:*@return *@return]     string
*/
Comp_Info.prototype.get_Titre = function()
{
 return this.str_Titre;
}

/**
*get_Description
*Retourne la description.
*
[mailto:*@return *@return]     string
*/
Comp_Info.prototype.get_Description = function()
{
 return this.str_Description;
}

/**
*get_Lien
*Retourne le lien.
*
[mailto:*@return *@return]     string
*/
Comp_Info.prototype.get_Lien = function()
{
 return this.str_Lien;
}

/**
*get_Date
*Retourne la date.
*
[mailto:*@return *@return]     string
*/
Comp_Info.prototype.get_Date = function()
{
 return this.str_Date;
}

/**
*get_Heure
*Retourne l'heure.
*
[mailto:*@return *@return]     string
*/
Comp_Info.prototype.get_Heure = function()
{
 return this.str_Heure;
}

/**
*get_Type
*Retourne le type.
*
[mailto:*@return *@return]     string
*/
Comp_Info.prototype.get_Type = function()
{
 return this.str_Type;
}

/**
*get_UrlImage
*Retourne l'url de l'image.
*
[mailto:*@return *@return]     string
*/
Comp_Info.prototype.get_UrlImage = function()
{
 return this.str_UrlImage;
}

<hr />Classe Comp_Infos qui gère plusieurs infos

<hr />/**
*Comp_Infos
*Constructeur de la classe Comp_Infos.
*
[mailto:*@return *@return]     void
*/
function Comp_Infos()
{
 this.array_Infos = new Array();
}

/**
*set_NouvelleInfo
*Ajoute une info.
*
[mailto:*@param *@param]     string
[mailto:*@param *@param]     string
[mailto:*@param *@param]     string
[mailto:*@param *@param]     string
[mailto:*@param *@param]     string
[mailto:*@param *@param]     string
[mailto:*@param *@param]     string
*
[mailto:*@return *@return]     void
*/
Comp_Infos.prototype.set_NouvelleInfo = function(str_Titre, str_Description, str_Lien, str_Date, str_Heure, str_Type, str_UrlImage)
{
 this.array_Infos[this.array_Infos.length] = new Comp_Info(str_Titre, str_Description, str_Lien, str_Date, str_Heure, str_Type, str_UrlImage);
}

/**
*check_Indice
*Vérifie la validité d'un indice.
*
[mailto:*@param *@param]     integer
*
[mailto:*@return *@return]     boolean
*/
Comp_Infos.prototype.check_Indice = function(int_Indice)
{
 if(this.array_Infos[int_Indice] != 'undefined')
  return true;
 else
  return false;
}

/**
*get_NbInfos
*Retourne le nombre total d'infos.
*
[mailto:*@return *@return]     integer
*/
Comp_Infos.prototype.get_NbInfos = function()
{
 return this.array_Infos.length;
}

/**
*get_UnTitre
*Retourne le titre d'une info.
*
[mailto:*@param *@param]     integer
*
[mailto:*@return *@return]     string
*/
Comp_Infos.prototype.get_UnTitre = function(int_Indice)
{
 if(this.check_Indice(int_Indice))
  return this.array_Infos[int_Indice].get_Titre();
 else
  return 'undefined';
}

/**
*get_UneDescription
*Retourne la description d'une info.
*
[mailto:*@param *@param]     integer
*
[mailto:*@return *@return]     string
*/
Comp_Infos.prototype.get_UneDescription = function(int_Indice)
{
 if(this.check_Indice(int_Indice))
  return this.array_Infos[int_Indice].get_Description();
 else
  return 'undefined';
}

/**
*get_UnLien
*Retourne le lien d'une info.
*
[mailto:*@param *@param]     integer
*
[mailto:*@return *@return]     string
*/
Comp_Infos.prototype.get_UnLien = function(int_Indice)
{
 if(this.check_Indice(int_Indice))
  return this.array_Infos[int_Indice].get_Lien();
 else
  return 'undefined';
}

/**
*get_UneDate
*Retourne la date d'une infos.
*
[mailto:*@param *@param]     integer
*
[mailto:*@return *@return]     string
*/
Comp_Infos.prototype.get_UneDate = function(int_Indice)
{
 if(this.check_Indice(int_Indice))
  return this.array_Infos[int_Indice].get_Date();
 else
  return 'undefined';
}

/**
*get_UneHeure
*Retourne l'heure d'une info.
*
[mailto:*@param *@param]     integer
*
[mailto:*@return *@return]     string
*/
Comp_Infos.prototype.get_UneHeure = function(int_Indice)
{
 if(this.check_Indice(int_Indice))
  return this.array_Infos[int_Indice].get_Heure();
 else
  return 'undefined';
}

/**
*get_UnType
*Retourne le type d'une info.
*
[mailto:*@param *@param]     integer
*
[mailto:*@return *@return]     string
*/
Comp_Infos.prototype.get_UnType = function(int_Indice)
{
 if(this.check_Indice(int_Indice))
  return this.array_Infos[int_Indice].get_Type();
 else
  return 'undefined';
}

/**
*get_UneUrlImage
*Retourne l'url de l'image d'une info.
*
[mailto:*@param *@param]     integer
*
[mailto:*@return *@return]     string
*/
Comp_Infos.prototype.get_UneUrlImage = function(int_Indice)
{
 if(this.check_Indice(int_Indice))
  return this.array_Infos[int_Indice].get_UrlImage();
 else
  return 'undefined';
}

<hr />Classe Comp_AfficheInfos qui gère l'affichage des infos (c'est la dedans que ça bug)

<hr />/**
*comp_AfficheInfos
*Constructeur de la classe comp_AfficheInfos.
*
[mailto:*@return *@return]     void
*/
function Comp_AfficheInfos(obj_CompInfos, str_IdCible, str_Prefixe, int_Vitesse, int_Attente, str_CurseurEcriture1, str_CurseurEcriture2, str_CurseurFin)
{
 this.obj_CompInfos = obj_CompInfos;
 if(document.getElementById)
  this.obj_Cible = document.getElementById(str_IdCible);
 else
  this.obj_Cible = 'undefined';
 
 this.int_IndiceInfo = 0;
 this.int_Taille = 0;
 this.str_Prefixe = str_Prefixe;
 this.int_Vitesse = int_Vitesse;
 this.int_Attente = int_Attente;
 this.str_CurseurEcriture1 = str_CurseurEcriture1;
 this.str_CurseurEcriture2 = str_CurseurEcriture2;
 this.str_CurseurFin = str_CurseurFin;
}

/**
*print_Info
*Affiche une info.
*
[mailto:*@return *@return]     void
*/
Comp_AfficheInfos.prototype.print_Info = function()
{
 if(this.obj_Cible != 'undefined' && this.obj_CompInfos.get_NbInfos() > 0)
 {
  var int_TimeOut;
  
  //initialisation des données
  str_Titre = this.obj_CompInfos.get_UnTitre(this.int_IndiceInfo);
  str_Description = this.obj_CompInfos.get_UneDescription(this.int_IndiceInfo);
  str_Lien = this.obj_CompInfos.get_UnLien(this.int_IndiceInfo);
  str_Date = this.obj_CompInfos.get_UneDate(this.int_IndiceInfo);
  str_Heure = this.obj_CompInfos.get_UneHeure(this.int_IndiceInfo);
  str_Type = this.obj_CompInfos.get_UnType(this.int_IndiceInfo);
  str_UrlImage = this.obj_CompInfos.get_UneUrlImage(this.int_IndiceInfo);
  
  str_MessageInfo = str_Description + ' [' + str_Date + ' ' + str_Heure + ']';
  str_Curseur = this.get_Curseur(str_MessageInfo.length);
  str_Info = str_Titre + ' : ' + str_MessageInfo.substring(0, this.int_Taille) + str_Curseur;
  
  //affiche l'info
  longueurCible = this.obj_Cible.firstChild.length;
  this.obj_Cible.firstChild.replaceData(0, longueurCible, str_Info);
  
  
  
  // Modifie la taille de la chaine ainsi que le timer
  if(this.int_Taille != str_Info.length)
  {
   this.int_Taille++;
   int_TimeOut = this.int_Vitesse;
  }
  else
  {
   this.int_IndiceInfo++;
   if(this.int_IndiceInfo >= this.obj_CompInfos.get_NbInfos())
    this.int_IndiceInfo = 0;
   this.int_Taille = 0;
   int_TimeOut = this.int_Attente;
  }
  
  //appelle en récursif de la fonction
  var Obj = this;
  setTimeout(Obj.print_Info(), int_TimeOut);  //le problème doit venir de quelque part par la ...
 }
}

/**
*get_Curseur
*Retourne le curseur actif.
*
[mailto:*@return *@return]     string
*/
Comp_AfficheInfos.prototype.get_Curseur = function(int_Taille)
{
 if(this.int_Taille == int_Taille)
  return this.str_CurseurFin;

 if((this.int_Taille % 2) == 1)
  return this.str_CurseurEcriture1;
 else
  return this.str_CurseurEcriture2;
}

2 réponses

cs_francois44 Messages postés 15 Date d'inscription jeudi 26 décembre 2002 Statut Membre Dernière intervention 17 novembre 2006
10 oct. 2006 à 10:57
Si ça peut aidé, voilà comment on s'en sert:

var obj_CompInfos = new Comp_Infos();
obj_CompInfos.set_NouvelleInfo('Mon Titre', 'Ma description', 'Mon lien', '09/10/06', '12:00', 'Mon Type', 'Mon image');
obj_CompInfos.set_NouvelleInfo('Mon Titre2', 'Ma description2', 'Mon lien2', '09/10/05', '12:00', 'Mon Type2', 'Mon image deux');
obj_CompInfos.set_NouvelleInfo('Mon Titre3', 'Ma description : trois', 'Mon lien3', '09/12/06', '12:56', 'Mon Type trois', 'Mon image 3');


var obj_AfficheInfos = new Comp_AfficheInfos(obj_CompInfos, 'tickerAnchor', 'INFOS : ', 50, 5000, '-', '>', '');
obj_AfficheInfos.print_Info();
0
cs_francois44 Messages postés 15 Date d'inscription jeudi 26 décembre 2002 Statut Membre Dernière intervention 17 novembre 2006
10 oct. 2006 à 10:59
Il faut bien sur avoir une balise nommé "tickerAnchor" dans le document ...

du genre:
0
Rejoignez-nous