Forums

ForumsProgramming Forum

Problem with object depths and duplications

Posted May 27, '08 at 12:46pm

Jcourtney

Jcourtney

8 posts

I'm currently having trouble with the depth of objects that I duplicate.

In this case I have a plane(s) that fly over and drop a bomb when I press SPACE. The more I press space, the more planes I get.

I didn't have any trouble with the depths of the planes, as I could easily get many on the screen. But when they are called to drop the bomb, the bombs appear, and when the next plane drops a bomb... the previous bomb is overwritten, or erased, and can be seen falling at the origin of the page(top left).

This is the script for the planes:

var i = 0;
var timer = 5;
this.onEnterFrame = function() {
    timer++;
    if (Key.isDown(Key.RIGHT)) {
        object._x += 5;
    }
    if (Key.isDown(Key.LEFT)) {
        object._x -= 5;
    }
    if (Key.isDown(Key.SPACE)) {
        if (timer>=5) {
            i++;
            _root.attachMovie("full_plane","full_plane"+i,_root.getNextHighestDepth());
            _root["full_plane"+i]._x = -15;
            _root["full_plane"+i]._y = Math.random()*250;
            timer = 0;
        }
    }
};

This is script for the bombs:

var k = 0;
dropped = false;
this.onEnterFrame = function() {
    this._x += 10;
    if (this._x>=_root.object._x) {
        if (!dropped) {
            k++;
            _root.attachMovie("bomb","bomb"+k,_root.getNextHighestDepth());
            _root["bomb"+k]._x = this._x;
            _root["bomb"+k]._y = this._y+3;
            dropped = true;
        }
    }
};

Can anyone explain how to fix this to me please?

Thanks.

 

Posted May 27, '08 at 12:48pm

Jcourtney

Jcourtney

8 posts

Note:

The first script is located in the main timeline, the second is located inside the timeline of the plane.

 

Posted May 29, '08 at 9:02am

dank

dank

1,043 posts

Knight

Instead of using getNextHighestDepth, try using a number (1000) then add i on to it. Give all the dupelicated MCs their own number, such as planes would be at 1000, bombs would be at 2000, etc.

 

Posted May 29, '08 at 1:16pm

MikeVarilek

MikeVarilek

38 posts

I don't see a problem with your code.
instead of this

k++;
            _root.attachMovie("bomb","bomb"+k,_root.getNextHighestDepth());
            _root["bomb"+k]._x = this._x;
            _root["bomb"+k]._y = this._y+3;

try this
depth = _root.getNextHighestDepth();
_root.attachMovie("bomb","bomb"+depth,depth);
currentBomb = eval("_root.bomb"+depth);
currentBomb._x = this._x;
currentBomb._y = this._y+3;

 

Posted May 29, '08 at 9:49pm

Jcourtney

Jcourtney

8 posts

depth = _root.getNextHighestDepth();
_root.attachMovie("bomb","bomb"+depth,depth);
currentBomb = eval("_root.bomb"+depth);
currentBomb._x = this._x;
currentBomb._y = this._y+3;

Thanks, MikeVarilek! It worked perfectly. I still don't know as to why the script I had didn't work.

 

Posted May 30, '08 at 1:02am

MikeVarilek

MikeVarilek

38 posts

No Problem

 
Reply to Problem with object depths and duplications

You must be logged in to post a reply!