I need help in something

i did a game, and there was two kindes of attached movie clips and i wrote this code at one cherecter:
[LEFT]

 [LEFT]_root.main1.onEnterFrame = function() {
    i++;
    if (Key.isDown(Key.CONTROL) and _root.am1.at1.w5._visible==1 and _root.ep1._width>=20 and sd==1) {
        sd=0;
        _root.main1.gokus.gotoAndPlay(97);
    }
    _root.attachMovie("disk","d"+i,i);
    _root["d"+i]._x=_root.main1._x;
    _root["d"+i]._y=_root.main1._y-10;
    if (_root.main1._xscale==100) {
        _root["d"+i].onEnterFrame = function() {
            this._x-=20;
        };
    }
    if (_root.main1._xscale==-100) {
        _root["d"+i].onEnterFrame = function() {
            this._x+=20;
        };
    }
};[/LEFT]

[/LEFT]

and in the 2nd one i wrote this:
[LEFT]

_root.main2.onEnterFrame = function() {
    t++;
    if (Key.isDown("90") and _root.am2.at2.w5._visible==1 and _root.ep2._width>=20 and sdt==1) {
        sdt=0;
        _root.main2.gokus.gotoAndPlay(97);
    }
    _root.attachMovie("disks","s"+t,t);
    _root["s"+t]._x=_root.main2._x;
    _root["s"+t]._y=_root.main2._y-10;
    if (_root.main2._xscale==100) {
        _root["s"+t].onEnterFrame = function() {
            this._x-=20;
        };
    }
    if (_root.main2._xscale==-100) {
        _root["s"+t].onEnterFrame = function() {
            this._x+=20;
        };
    }
};

when i did this and sometimes press Ctrl and “z” at the same time the 2nd movie clip wasnt attached and it was only playing frame 97
but when i put the code of the attachment in frame 97 it worked, why is thet?
thanks for the helpers[/LEFT]

this is probably because you have the gotoAndPlay(97) frame before you have the attach movieClip code try moving the first if statement to the bottom of your code and see if that helps.

no its not it man…:puzzled:

alright what do you have your i and t variable intialize at? … if they are the same, then you are overwriting the movieclip in that depth

so let’s say you have them both set to zero

var i = 0;
var t = 0;

if you hit the buttons at teh same time only one will show because they are both trying to place a movieclip into depth level 0.

so trying starting them off at different values like
var i = 0;
var t = 100;

just so they don’t overlap, only issue i can see with this is if they keep hitting the button to trigger i and not t then you’ll wind up back to where you are now like so

i == 100;
and
t == 100;

if they hit both those buttons again at the same time you will get the same problem.

you might need to do some other check like


// in your first bit of code before after i++;
i++;
if(i >= 99){
    i = 0;
}
// rest of code here ....
// then have t something like
t++;
if(t >= 199){
    t = 100;
}
// other code ...

hope this helps

the "i’ and “t” they are in two different movieclips ,it could be thet “i” is bigger then “t” and [“s”+t] is not showen?i have notice thet when i put:

_root.attachMovie("disks","s"+t,t*100)

so it attaching it right:s:
can u explain me the meaning of the depths please?
tnx

well the last number you are putting in the attachmovie is the depth level in this case the t*100

2 movieClips cannot stay inside the same depth level … so if you do the following


t++;
_root.attachMovie("disks","s"+t, 100)
t++;
_root.attachMovie("disks","s"+t, 100)

this will generate 2 new movie clips but since the second one is being attached to the same depth level 100, it will replace whatever was in it before

think of depths as layers in the actual fla, you can put movieClips above and below each other using layers and you can swap the layers

if you look up swapDepths in the flash help you might get a better understanding for depths

hope this helps

_root.main1.onEnterFrame = function() {
     if (Key.isDown(Key.CONTROL) && _root.am1.at1.w5._visible && _root.ep1._width>=20 && sd) {
        sd=0;
        _root.main1.gokus.gotoAndPlay(97);
    }
    _root.attachMovie("disk","d"+i,i++,{_x:_root.main1._x, _y:_root.main1._y-10});
    if (_root.main1._xscale==100) {
        _root["d"+i].onEnterFrame = function() {
            this._x-=20;
        };
    } else if (_root.main1._xscale==-100) {
        _root["d"+i].onEnterFrame = function() {
            this._x+=20;
        };
    }
};

_root.main2.onEnterFrame = function() {
    if (Key.isDown("90") && _root.am2.at2.w5._visible && _root.ep2._width>=20 && sdt) {
        sdt=0;
        _root.main2.gokus.gotoAndPlay(97);
    }
    _root.attachMovie("disks","s"+t,t++, {_x:_root.main2._x, _y:_root.main2._y-10;});
    if (_root.main2._xscale==100) {
        _root["s"+t].onEnterFrame = function() {
            this._x-=20;
        };
    }else if (_root.main2._xscale==-100) {
        _root["s"+t].onEnterFrame = function() {
            this._x+=20;
        };
    }
};

-Use AS tags when posting
-That’s just a shortened version of what you have already… post a fla?
-Optix, You can’t have two objects at the same depth, one will be removed.

so if its the same depths some movie clip will be removed? but why?

not sure why, flash just dont like it

lol… but im right?

-Optix, You can’t have two objects at the same depth, one will be removed.

But that’s what i was saying all along … did i say something wrong?

and yes flamer you are correct

the first movieClip in the depth will be replaced with which ever MovieClip you try to put into it

:slight_smile: