begin process at 2012 02 09 17:10:28
  Trouver un code source :
 
dans
 
Accueil > Forum > 

Flash / Flash MX

 > 

Scripts

 > 

ActionScript

 > 

Mon code mange toute la mémoire !


Derniers messages déposésPoser une question dans le forum ou lancer une discussion

Mon code mange toute la mémoire !

mardi 20 février 2007 à 16:18:40 | Mon code mange toute la mémoire !

barn333

Bonjour, je suis un super noob et je bricole des trucs en récupérant des fragments de code ici et là. l'anime tourne bien mais ralentir fortement au bout d'un certain temps je pense que le problème vient des nombreuses variables qui restent après utilisations mais je ne sais pas trop comment les gérer. merci d'avance pour vos conseils voici le code : // menu bneutre.swapDepths(1000000); borange.swapDepths(1000001); brouge.swapDepths(1000002); bvert.swapDepths(1000003); bnoir.swapDepths(1000004); bbleu.swapDepths(1000005); bneutre.onPress = function() { Entite.apply(); } borange.onPress = function() { nb_orange++ ; Orange.apply(); } brouge.onPress = function() { nb_rouge++ ; Rouge.apply(); } bvert.onPress = function() { nb_vert++ ; Vert.apply(); } bnoir.onPress = function() { nb_noir++ ; Noir.apply(); } bbleu.onPress = function() { nb_bleu++ ; Bleu.apply(); } // params control = "ok"; repr = "ok"; repo = "ok"; repv = "ok"; repn = "ok"; repb = "ok"; LARG = Stage.width; HAUT = Stage.height; nb_points_courbe = 12; nb_entite = 0; tb_entite = []; nb_orange = 0; tb_orange = []; nb_rouge = 0; tb_rouge = []; nb_vert = 0; tb_vert = []; nb_noir = 0; tb_noir = []; nb_bleu = 0; tb_bleu = []; _global.PI_4 = Math.PI / 4; /// ------Creation bordure -------- _root.createEmptyMovieClip("circuit", 100); // ----------------entite---------------------------------------- Entite = function(caste,val) { this.caste = "entite"; this.val = "vale"; nb_entite++; var entite = _root.createEmptyMovieClip(caste + "_" + nb_entite, 20000 + nb_entite); tb_entite.push(entite); entite.lineStyle(9, 0xcccccc); entite.lineTo(0, 1); entite.lineStyle(5, 0xffffff); entite.lineTo(0.2, 0.2); entite._x = LARG / 3 + Math.floor(Math.random()*333+1) ; entite._y = HAUT / 3 + Math.floor(Math.random()*333+1) ; entite.vitesse = 0; entite.virage = 0; entite.vitesse_maxi = 10// + nb_entite / 5; var palp = _root.createEmptyMovieClip("palpeur_" + nb_entite, -1500 + nb_entite); entite.palpeur = palp; // val orange if (val == "valo") { entite.lineStyle(9, 0xcc6600); entite.lineTo(0, 10); entite.lineStyle(6, 0xff9900); entite.lineTo(0.2, 0.2); tb_orange.push(entite); } // val rouge if (val == "valr") { entite.lineStyle(9, 0xaa0000); entite.lineTo(0, 10); entite.lineStyle(6, 0xff5555); entite.lineTo(0.2, 0.2); tb_rouge.push(entite); } // val vert if (val == "valv") { entite.lineStyle(9, 0x00aa00); entite.lineTo(0, 10); entite.lineStyle(6, 0x00ff00); entite.lineTo(0.2, 0.2); tb_vert.push(entite); } // val noir if (val == "valn") { entite.lineStyle(9, 0x000000); entite.lineTo(0, 10); entite.lineStyle(6, 0xaaaaaa); entite.lineTo(0.2, 0.2); tb_noir.push(entite); } // val bleu if (val == "valb") { entite.lineStyle(9, 0x0000aa); entite.lineTo(0, 10); entite.lineStyle(6, 0x5555ff); entite.lineTo(0.2, 0.2); tb_bleu.push(entite); } // ------- supprimer--------------- MovieClip.prototype.confrontation = function(){ if (control == "ok") { for (var i = 0; i < nb_entite+1; i++) { for (var j = 0; j < nb_entite+1; j++) { vicr = tb_rouge[i]; vicv = tb_vert[i]; vico = tb_orange[i]; vicn = tb_noir[i]; vicb = tb_bleu[i]; // ---sup rouge-------- if (vicr.hitTest(tb_orange[j]) || vicr.hitTest(tb_noir[j])) { removeMovieClip(vicr); nb_rouge-- ;} // ---sup orange-------- if (vico.hitTest(tb_vert[j])) { removeMovieClip(vico); nb_orange-- ;} // ---sup vert-------- if (vicv.hitTest(tb_noir[j]) || vicv.hitTest(tb_rouge[j])) { removeMovieClip(vicv); nb_vert-- ;} // ---sup noir-------- if (vicn.hitTest(tb_orange[j])) { removeMovieClip(vicn); nb_noir-- ;} // ---sup bleu-------- if (vicb.hitTest(tb_noir[j]) || vicb.hitTest(tb_rouge[j]) || vicb.hitTest(tb_vert[j])) { removeMovieClip(vicb); nb_bleu-- ;} }}} }; // ------- reproduction--------------- MovieClip.prototype.reproduction = function(){ if (control == "ok") { for (var i = 0; i < nb_entite+1; i++) { for (var j = 0; j < nb_entite+1; j++) { // ---rep rouge-------- if (repr == "ok" && i != j && tb_rouge[i].hitTest(tb_rouge[j])) { nb_rouge++ ; Rouge.apply(); repr = "bad";} // ---rep orange-------- if (repo == "ok" && i != j && tb_orange[i].hitTest(tb_orange[j])) { nb_orange++ ; Orange.apply(); repo = "bad";} // ---rep vert-------- if (repv == "ok" && i != j && tb_vert[i].hitTest(tb_vert[j])) { nb_vert++ ; Vert.apply(); repv = "bad";} // ---rep noir-------- if (repn == "ok" && i != j && tb_noir[i].hitTest(tb_noir[j])) { nb_noir++ ; Noir.apply(); repn = "bad";} // ---rep bleu-------- if (repb == "ok" && i != j && tb_bleu[i].hitTest(tb_bleu[j])) { nb_bleu++ ; Bleu.apply(); repb = "bad";} if (repb == "ok" && i != j && tb_bleu[i].hitTest(tb_orange[j])) { nb_bleu++ ; Bleu.apply(); repb = "bad";} }} control = "bad";} }; }; // fin création entite // orange ------- Orange = function() { var orange = new Entite("orange", "valo"); }; // rouge ------- Rouge = function() { var rouge = new Entite("rouge", "valr"); }; // vert ------- Vert = function() { var vert = new Entite("vert", "valv"); }; // noir ------- Noir = function() { var noir = new Entite("noir", "valn"); }; // bleu ------- Bleu = function() { var bleu = new Entite("bleu", "valb"); }; // -------creation des points d'ancrage de la bordure ---- tb = []; for (var i = 0; i < nb_points_courbe; i++) { tb[i] = createEmptyMovieClip("c" + i, i); phase = 2 * Math.PI * i / nb_points_courbe; with (tb[i]) { lineStyle(0, 0, 0); lineTo(0, 1); _x = LARG / 2 + LARG / 2 * Math.sin(phase); _y = HAUT / 2 + HAUT / 2 * Math.cos(phase); } tb[i]._x0 = tb[i]._x; tb[i]._y0 = tb[i]._y; } // --------permet de tracé de la bordure ----------- MovieClip.prototype.polycourbe_JL = function(epaisseur, couleur, transparence) { this.clear(); this.beginFill(couleur, 100); this.moveTo(0, 0); this.lineTo(LARG, 0); this.lineTo(LARG, HAUT); this.lineTo(0, HAUT); this.lineTo(0, 0); this.lineStyle(epaisseur, couleur, transparence); // ---------------------------- var ptx; var pty; var i = 0; var ptx0 = (tb[0]._x + tb[1]._x) / 2; var pty0 = (tb[0]._y + tb[1]._y) / 2; this.moveTo(ptx0, pty0); var i = 0; while (++i < tb.length - 1) { ptx = (tb[i]._x + tb[i + 1]._x) / 2; pty = (tb[i]._y + tb[i + 1]._y) / 2; this.curveTo(tb[i]._x, tb[i]._y, ptx, pty); } ptx = (tb[0]._x + tb[i]._x) / 2; pty = (tb[0]._y + tb[i]._y) / 2; this.curveTo(tb[i]._x, tb[i]._y, ptx, pty); this.curveTo(tb[0]._x, tb[0]._y, ptx0, pty0); this.lineStyle(0, couleur, transparence); this.endFill(); }; // ---------permet des mouvements harmonieux ------------ MovieClip.prototype.ANGUINEA = function(obj, duree, rebond) { //rebond = 0 ou inexistant --> normal, entre 0 et 1 rebond, conseil .7 this.ANGUI = {FL: true, OB: obj, TB: [], PT: 0}; var inc = 1 / duree; for (var n = 0; n <= 1.0; n += inc) { var s = 1 - (2 - rebond) / (n + (1 / n * (1 - rebond))); for (var prop in this.ANGUI.OB) { this.ANGUI.TB.push(this.ANGUI.OB[prop] - s * (this.ANGUI.OB[prop] - this[prop])); } } this.ID_ANGUINEA = setInterval(function (_this) { var control_fin = (_this.ANGUI.PT >= _this.ANGUI.TB.length); for (var prop in _this.ANGUI.OB) { _this[prop] = (control_fin) ? _this.ANGUI.OB[prop] : _this.ANGUI.TB[_this.ANGUI.PT++]; } if (control_fin) { delete _this.ANGUI; clearInterval(_this.ID_ANGUINEA); } }, duree, this); }; //--------mouvement de la bordure ---------------- hasard_bordure = function () { h = (h++ >= tb.length) ? 0 : h; var phase = 2 * Math.PI * h / tb.length; var px = tb[h]._x0 + random(LARG / 60) * Math.sin(phase); var py = tb[h]._y0 + random(HAUT / 60) * Math.cos(phase); clearInterval(this.ID_ANGUINEA); tb[h].ANGUINEA({_x: px, _y: py}, 50, .9); // --- ramener le robot sil sort de l'écran-- for (var j = 0; j < nb_entite; j++) { var entite = tb_entite[j]; if (entite._x < 0 || entite._x > LARG || entite._y < 0 || entite._y > HAUT) { entite._x = entite._y = HAUT / 2; } } }; // ------- mouvement du robot --------------- MovieClip.prototype.bouger = function() { this.vitesse += (this.vitesse_maxi - this.vitesse) / 12; var rot = this._rotation * Math.PI / 180; this._x += Math.sin(rot) * this.vitesse; this._y -= Math.cos(rot) * this.vitesse; }; // ---- test de chocs du robot avec son environnement --------- MovieClip.prototype.test_contact = function(autre_clip) { this._rayon = 3 + this.vitesse * 5; this._rayon_AV = 2 * this._rayon; var rot = this._rotation * Math.PI / 180; rot_plus_PI_4 = rot + PI_4; rot_moin_PI_4 = rot - PI_4; rot_plus_PI_4_AV = rot + .08; rot_moin_PI_4_AV = rot - .08; this.x1 = this._x + Math.sin((rot_plus_PI_4)) * this._rayon; this.y1 = this._y - Math.cos((rot_plus_PI_4)) * this._rayon; if (autre_clip.hitTest(this.x1, this.y1, true)) { this.virage = -2 * (this.vitesse_maxi - this.vitesse); this._rotation += this.virage; this.vitesse *= .8; } this.x2 = this._x + Math.sin((rot_moin_PI_4)) * this._rayon; this.y2 = this._y - Math.cos((rot_moin_PI_4)) * this._rayon; if (autre_clip.hitTest(this.x2, this.y2, true)) { this.virage = 2 * (this.vitesse_maxi - this.vitesse); this._rotation += this.virage; this.vitesse *= .8; } this.x3 = this._x + Math.sin(rot_plus_PI_4_AV) * this._rayon_AV; this.y3 = this._y - Math.cos(rot_plus_PI_4_AV) * this._rayon_AV; if (autre_clip.hitTest(this.x3, this.y3, true)) { this._rotation += this.virage; this.vitesse *= .4; } this.x4 = this._x + Math.sin(rot_moin_PI_4_AV) * this._rayon_AV; this.y4 = this._y - Math.cos(rot_moin_PI_4_AV) * this._rayon_AV; if (autre_clip.hitTest(this.x4, this.y4, true)) { this._rotation += this.virage; this.vitesse *= .4; } //this.Representer_palpeurs(); }; // ------------------------------------------------------- MovieClip.prototype.Representer_palpeurs = function() { with (this.palpeur) { clear(); lineStyle(0, 0xff0000, 20); moveTo(this.x1, this.y1); lineTo(this.x1, this.y1); lineTo(this.x3, this.y3); lineTo(this.x4, this.y4); lineTo(this.x2, this.y2); } }; // -------------faire bouger ------------------------------------------ function faire_bouger() { for (var i = 0; i < nb_entite; i++) { for (var j = 0; j < nb_entite; j++){ if (i != j) { tb_entite[i].test_contact(tb_entite[j]); } } tb_entite[i].test_contact(_root.circuit); tb_entite[i].bouger(); tb_entite[i].confrontation(); tb_entite[i].reproduction(); } } // ------------------------------------------------------- tracer_circuit = function () { circuit.polycourbe_JL(10, 0x999999, 100); }; // ----------- controltest -------- controltest = function () { if( control == "bad"){ control = "ok";} else { control = "bad";} }; // -----------compteur repro -------------------------------------------- repgor = function () { repr = "ok"; }; repgoo = function () { repo = "ok"; }; repgov = function () { repv = "ok"; }; repgon = function () { repn = "ok"; }; repgob = function () { repb = "ok"; }; setInterval(controltest, 100); setInterval(tracer_circuit, 70); setInterval(faire_bouger, 15); setInterval(hasard_bordure, 500); setInterval(repgor, 4000); setInterval(repgoo, 5000); setInterval(repgov, 4000); setInterval(repgon, 6000); setInterval(repgob, 2500); stop();
mardi 20 février 2007 à 16:21:07 | Re : Mon code mange toute la mémoire !

barn333

cela aurait été surement mieux avec des retours à la ligne ... ^^'
mardi 20 février 2007 à 20:28:40 | Re : Mon code mange toute la mémoire !

Darkrats

Sans vouloir être défetiste ... mais je crois que tu n'auras jamais de réponse avec un message comme ça

En tout cas, pas par moi, j'ai abandonné après le 3ème mot

Sorry


Bon, j'ai lu la première ligne ...
Pour la variables, celles définies dans un calque sont gardées en mémoire ... tandis que celles créées dans une fonction sont effacées une fois la fonction terminée.

Pour le reste, je peux pas t'aider, j'arrive pas à lire la suite sans une présentation correcte ... Ca serait bien aussi (si tu réécris le code) de dire à quoi il sert. Ca aidera éventuellement pour trouver la solution.
mercredi 21 février 2007 à 14:38:10 | Re : Mon code mange toute la mémoire !

barn333

je crois que l'on peut supprimer ce post, j'en ferais un autre plus tard un peu plus clair


Cette discussion est classée dans : function, math, nb, tb, entite


Répondre à ce message

Sujets en rapport avec ce message

faire une pause dans une animation [ par earthworms ] Bonjour a tous,J'ai trouvé un tutorial qui m'expliquait comment créer un feu d'artifice. Jusque la tout va bien, je suis tout content, je le modifie a Textfields : problème de chargement de variable [ par maskim ] bonsoir, depuis hier apres midi (et aujourd'hui une bonne partie de la journée), j'essaie de charger du texte dans des textfields, pour une liste de Plusieurs boutons pour charger plusieurs images [ par Robby666 ] Bonsoir à tous,voilà mon problème, je suis en train de m'apprendre flash en construisant un petit jeu de plateau façon jeu de l'oie (sous forme de qui stopper un carrousel sur un angle prédéfini [ par neuronezero ] Alors voilà mon problème...J'ai fais un carrousel tout simple en AS2, mais je désirerais faire en sorte que quand je clik sur l'un des objets le carro lecteur flv en as2 à passer en as3 [ par punkprod ] salut à tous!grâce à un tuto pas mal, j'ai réussi à réaliser un lecteur flv en as2, mais j'aimerais le passer en as3, et comme je débute dans ce langu problème d'amélioration de polaroid galery [ par lirisnocif ] Bonjour je souhaite utiliser cette galerie :http://www.no3dfx.com/polaroid/après avoir effectué plusieurs modifications pour remanier le script à ma f LocalConnection et image [ par momo74230 ] bonjour à tous et toutes..grace à LocalConnection je passe l'ordre de charger une image de mon emeteur à mon recepteur:emeteuremission_lc = new LocalC un menu à refaire [ par tonydanza ] Bonjour,J'espère que vous pourrez m'aider,j'ai une galerie avec un bouton "aller" et un bouton "retour"ça fait défiler les images issue d'un xml ...je scroll ne s'arrête pas au bas du texte [ par Baby Jane ] Bonjour,J'ai réalisé un vertical scrollbar pour un site entièrement en flash 8. Je souhaite que lorsque le scrollFace est au bas de mon scrollTrack, c jquery / Mootools non compatible ? [ par dreadstock ] Bonjour à tous ,Je suis en train de créer un site web pour mon frangin. Je souhaite intégrer 2 bibliothèques jquery et mootools plus particulierement


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 1,763 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales