Probleme _root

martialb75 Messages postés 5 Date d'inscription mardi 19 avril 2005 Statut Membre Dernière intervention 6 mars 2007 - 6 mars 2007 à 13:39
Mansuz Messages postés 169 Date d'inscription lundi 11 décembre 2006 Statut Membre Dernière intervention 25 janvier 2014 - 6 mars 2007 à 19:35
Bonjour, J'utilise flash plus comme un designer qu'un codeur.
J'ai téléchargé les sources d'un jeux simple mais fun.
Il fonctionne a merveille mais je voudrais que ce jeux soit dans un movie clip (que je nommerai mc_game) qui se trouvera sur la scène principale. Or quand je fais ca et que je change les _root en _root.mc_game, ca ne fonctionne pas.
A vrai dire, je suis perdu.
Voic le lien du jeux pour vous rendre compte : www.martialb.com/blocks.html
Voici le code :

// reset variables and place tiles
function resetTiles() {
x=0; y=0;
while(x<10) {
while(y<10) {
duplicateMovieClip("tiles","t"+ x + "_" + y, ++d);
t=this["t"+ x + "_" + y];
t._x= (x*28);
t._y= (y*28);
c=int(random(4))+1;
t.col=c;
t.state=true;
t.gotoAndStop(c);
t.x=x;
t.y=y;
y++;
}
y=0;
x++;
}
}


// find and remove same color tiles
function findTile(x,y) {
col =_root["t"+ x + "_" + y].col;
if ((_root["t"+ (x-1) + "_" + y].col == col) or (_root["t"+ (x+1) + "_" + y].col == col) or (_root["t"+ x + "_" + (y-1)].col == col) or (_root["t"+ x + "_" + (y+1)].col == col)) {
_root["t"+ x + "_" + y].state=false;
_root["t"+ x + "_" + y].gotoAndStop(5);
tiles--;
sc++;
if ((_root["t"+ (x-1) + "_" + y].col == col) and (_root["t"+ (x-1) + "_" + y].state==true)) {findTile((x-1),y); }
if ((_root["t"+ (x+1) + "_" + y].col == col) and (_root["t"+ (x+1) + "_" + y].state==true)) {findTile((x+1),y); }
if ((_root["t"+ x + "_" + (y-1)].col == col) and (_root["t"+ x + "_" + (y-1)].state==true)) {findTile(x,(y-1)); }
if ((_root["t"+ x + "_" + (y+1)].col == col) and (_root["t"+ x + "_" + (y+1)].state==true)) {findTile(x,(y+1)); }
_root["t"+ x + "_" + y].col=0;

}
}

// check tile and below it
function checkTile() {
x=0; y=0;
while(x<10) {
while(y<9) {
if ((_root["t"+ x + "_" + (y+1)].col ==0) and (_root["t"+ x + "_" + y].col != 0)) {replaceColors(x,y); checkTile();}
y++;
}
y=0;
x++;
}
}

// replace tile colors
function replaceColors(px,py) {
c=_root["t"+ px + "_" + py].col;
_root["t"+ px + "_" + (py+1)].col = c;
_root["t"+ px + "_" + (py+1)].state = true;
_root["t"+ px + "_" + (py+1)].gotoAndStop(c);
_root["t"+ px + "_" + py].state=false;
_root["t"+ px + "_" + py].col=0;
_root["t"+ px + "_" + py].gotoAndStop(5);
}


// add score points, show text clip
function addScore(x,y) {
if (sc>1) {
textClip.swapDepths(++d);
textClip._x=x;
textClip._y=y;
if (sc<10) {
score+=sc*100;
pos=sc*35;
textClip.gotoAndPlay(pos);
clickSound.gotoAndPlay(2);}
else {
score+=2000;
textClip.gotoAndPlay(350);
clickSound.gotoAndPlay(5);}
}
if(tiles==0) {wellDone.gotoAndPlay(2);}
}


// start game
playing=1;
d=0; sc=0; score=0; tiles=100;
resetTiles();
stop();

Merci pour votre aide.

1 réponse

Mansuz Messages postés 169 Date d'inscription lundi 11 décembre 2006 Statut Membre Dernière intervention 25 janvier 2014 1
6 mars 2007 à 19:35
Salut,
Le mieux c'est d'essayer de faire son propre code, c'est souvent plus simple à comprendre.^^
Même si ca prends un peu plus longtemps.

La prochaine fois essaye de ranger le code comme ceci:

// reset variables and place tiles

function resetTiles() {

x=0; y=0;
while(x<10) {
while(y<10) {
duplicateMovieClip("tiles","t"+ x + "_" + y, ++d);
t=this["t"+ x + "_" + y];
t._x= (x*28);
t._y= (y*28);
.................
......
...
C'est juste plus simple de lecture.
0
Rejoignez-nous