Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Duplicate movie question 1

Status
Not open for further replies.

Adam14

Technical User
Nov 8, 2003
193
CA
Hey guys, I'm having a problem with duplicating a "laser"MC in a simple shooting scenario. If I have one laser shooting from the middle of my ship, it's fine, but if I try to have two lasers, one from each of the wings, only the second one fires. Here's the code I'm using. Any ideas?

on (press) {
ship._x = getProperty(_root.ship, _x);
ship._y = getProperty(_root.ship, _y);
duplicateMovieClip (_root.laser, "laser"+n, n);
setProperty ("laser"+n, _x, ship._x+20);
setProperty ("laser"+n, _y, ship._y);
n++;
duplicateMovieClip (_root.laserb, "laser"+i, i);
setProperty ("laser"+i, _x, ship._x-20);
setProperty ("laser"+i, _y, ship._y);
i++;
}
This is attached to a button I have in the main movie, which only shoots "laserb"'s duplicates.

Whereas, if I remove the second laser script("laserb" duplicateMovieClip), it shoots "laser" correctly. Any help is always appreciated.
Thanks,
Adam
 
instead of duplicating "laser"MC for both guns, you should probably create a separate movie clip for each gun. i'm sure this is workable but that would be a quick fix
 
Thanks for gettin' back so quick. I actually have laserMC, and laserbMC. I'm trying to get both of them to duplicate. Unless I can get one to duplicate two lasers and set different _x postions for each. I just get frustrated at times trying to figure these things out that by the time I give up and come to see if someone here can help, I don't usually have enough marbles left to fully explain myself. And, hey nothing wrong with a quick fix.

Thanks,
Adam
 
if you want me to take a look send me your fla...

i just worked on something similar so i can see if i can find a similar solution...

shellojj@email.uc.edu
 
I forgot to mention, I'm working with Flash 5 :(
 
ok... i got it...

i'm working in MX so i hope it works the same in 5...

on (press) {
ship._x = getProperty(_root.ship, _x);
ship._y = getProperty(_root.ship, _y);
duplicateMovieClip (_root.laser, "laser"+n, n);
setProperty ("laser"+n, _x, ship._x+20);
setProperty ("laser"+n, _y, ship._y);

duplicateMovieClip (_root.laserb, "laserb"+n, x++);
setProperty ("laserb"+n, _x, ship._x-20);
setProperty ("laserb"+n, _y, ship._y);
n++;
x++;
}
 
That works perfect!!! So, it wasn't working because it had the same depth? Is that what you changed? The reason I'm asking is I'm trying to use the attachMC, to get the ship to go from a one gun ship to a two gun ship, when it hits a "power pellet", but I think it's not working because of the depths. Thanks you so much, here's a star!

Adam
 
you had...

duplicateMovieClip (_root.laserb, "laser"+n, i)

i changed the depth and the second parameter "newname" because they both had the name "laser"...

the only other problem i see is that you might want to use an array instead of layers(depth) because the depth will continue to increase and create unnecessary build up...
 
I've just been reading about arrays, and only been learning actionscript for a couple weeks now. I wonder if you might be able to explain this one to me:(I know you've helped me enough already, so if you need to skip this, I understand). I have the one gun ship in frame 1, and the three gun ship in frame three. I have this script on the shipMC in frame 1:

onClipEvent (enterFrame) {
if (_root.ship.hitTest(_root.PowerPellet)) {
_root.ship.attachMovie("ships2", "twoguns", 1);
setProperty ("_root.PowerPellet", _visible, 0);
gotoAndStop (3);
}
}

the first two actions work; the attachMovie, and setProperty, but it doesn't go to frame 3 - which is where I have the revised script that you did for me. Any ideas? I've been working on this since before my last post, and finally had to grab beers to hopefuly make sense of things :)

I've once again attached the fla in case you need clarification:


Thanks,
Adam
 
I figured it out, after hours of trying everything I could think of, I added a _root before the gotoAndStop, and voila!

Thanks again for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top