PDA

View Full Version : using attachMovieClip() with multiple attachments!


BioAndy
10-03-2005, 11:21 PM
Hey everyone, im new here but glad to be apart of the forums now.

Hopefully my knowledge can help everyone else here also!!
Anyway what brought me here is im having some trouble with a piece of my code.

As the title implies im trying to attach multiple mc's.

Here is what my code looks like.


// For onClipEvent(load)
function buildBlocks()
{
for(i = 0; i < 10; i++)
{
_root.attachMovie("Blue", "BlueDup" +i,i);
_root["BlueDup"+i]._x = i * 75 + 25;
_root["BlueDup"+i]._y = 0;

}
}

// For onClipEvent(enterFrame)
function actionBlocks()
{

for(i = 0; i < 10; i++)
{
if (_root["ball"].hitTest (_root["BlueDup"+i]))
{
_root.ball.speedY *= -1;
_root["BlueDup"+i].removeMovieClip();
return;
}
}
}


Now all of this works great. What doesnt work so well is when im trying to attach another movie clip as the following shows.

// For onClipEvent(load)
function buildBlocks()
{
for(i = 0; i < 10; i++)
{
_root.attachMovie("Blue", "BlueDup" +i,i);
_root["BlueDup"+i]._x = i * 75 + 25;
_root["BlueDup"+i]._y = 0;

}
for(i = 11; i < 21; i++)
{
_root.attachMovie("Green", "GreenDup" +i,i);
_root["GreenDup"+i]._x = i * 75 + 25;
_root["GreenDup"+i]._y = 15;
}
}


Now i know there is the whole thing to depth and levels. Always get them confused and i havent worked that much with the attachMovieClip() before.

So can anyone tell me what im doing wrong here?

Thanks everyone.
Andy

deadbeat
10-03-2005, 11:25 PM
Welcome to AS.org!

What exactly is the problem you're having?

K.

BioAndy
10-03-2005, 11:29 PM
Well as shown in my 2nd code script im attempting to attach an additional mc.

But when i do this and i test my file it overlaps the first mc i attached. Why i feel this is a problem with depth/levels.

But i've been toying with this code for about 3 hours trying different configurations but nothing is working lol

Maybe it's one of those pieces of code where i should leave it alone for 4 or 5 hours, let my head sit on it and than when i come back to the computer its fixed within 5 minutes LOL

Hate and love when that happens.

BioAndy
10-04-2005, 02:15 AM
Just wanted to post that this has been solved.

Here's the code in case anyone is wondering. Basically this takes and attaches a mc object in the library and duplicates the object. I use the object for my game's ball to destroy.

I havent added it yet (time for sleep) but with the var game.numberOfTypes you can add different variations of the objects in the main linked objects timeline.


game = {};
game.columns = 10;
game.rows = 4;
game.spacing = 15;
game.depth = 1000;
game.path = _root.Blue;
game.numberOfTypes = 1;

// For onClipEvent(load)
function buildBlue()
{
for (var j = 1; j <= game.rows; ++j)
{
for (var i = 1; i <= game.columns; ++i)
{
var name = "BlueDup" + i + "_" + j;
var x = (i-1)* 75 + 25;
var y = (j-1)* 15;
var type = 1;
_root.attachMovie("Blue", name, ++game.depth);
_root[name]._x = x;
_root[name]._y = y;
game[name] =
{
x:i, y:j, name:name, type:type, clip:_root[name]
};
}
}
}

// For onClipEvent(enterFrame)
function actionBlue()
{
for (var j = 1; j <= game.rows; ++j)
{
for (var i = 1; i <= game.columns; ++i)
{
var name = "BlueDup" + i + "_" + j;

if (_root["ball"].hitTest (_root[name]))
{
_root.ball.speedY *= -1;
_root[name].removeMovieClip();
return;
}
}
}
}


All this code is placed in an external .as file.
And to call it i just use

onClipEvent(load)
{
#include "Include\functionBlock.as"
buildBlue();
}

onClipEvent(enterFrame)
{
actionBlue();
}


With a movie clip object i have outside of the game area.
You could put all the code in a movie clip in the game area but i dont really care for the flash (i use ver 8) actionscript viewer setup. I even use dual monitor for all my programming. But with external .as files you get the whole screen for the viewer :P