# Problem duplicating a scrolling mc and removing laser

**URL:** https://forum.kirupa.com/t/problem-duplicating-a-scrolling-mc-and-removing-laser/56276
**Category:** Uncategorized
**Created:** [July 2, 2004, 6:00am UTC](https://forum.kirupa.com/t/problem-duplicating-a-scrolling-mc-and-removing-laser/56276 "2004-07-02T06:00:11Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![mixedtrigeno](https://avatars.discourse-cdn.com/v4/letter/m/3da27b/32.png) [@mixedtrigeno](https://forum.kirupa.com/u/mixedtrigeno)
#### Post date: [July 2, 2004, 6:00am UTC](https://forum.kirupa.com/t/problem-duplicating-a-scrolling-mc-and-removing-laser/56276/1 "2004-07-02T06:00:11Z")

</div>

im almost done with my game but i have two problems.

1. when the laser hits and enemy it doesn’t disappear instead it keeps going through enemies until its out of the screen.  
-i tried to add a removemovieclip to it but when i did it it removed the laser that you cant even shot no more.hehe

2)when i move forward the stars scroll fine but when that one reaches the end of the end the other stars that is suppose to be respawn .respawns at the same spot i had the other one previously. i dont know if i am explaining this the right way.

this is the code on the on the spaceship:

```auto
onClipEvent (load) {
 moveSpeed = 15;
 _root.laser._visible = false;
 laserCounter = 1;
 _root.missile._visible = false;
 missileCounter = 1;
 scrollx = _root.mainGround.ground._width/3;
 scrollStart = false;
 maxLasers = 4;
 maxMissile = 1;
 depthCounter = 1;
 depthCounters = 10;
 enemie **** = 0;
}
onClipEvent (enterFrame) {
 if (Key.isDown(Key.SPACE) and (laserCounter<=maxLasers)) {
  laserCounter++;
  _root.laser.duplicateMovieClip("laser"+depthCounter, depthCounter);
  _root["laser"+depthCounter]._visible = true;
  depthCounter++;
  if (depthCounter>maxLasers) {
   depthCounter = 1;
  }
 }
 if (Key.isDown(Key.CONTROL) and (missileCounter<=maxMissile)) {
  missileCounter++;
  _root.missile.duplicateMovieClip("missile"+depthCounters, depthCounters);
  _root["missile"+depthCounters]._visible = true;
  depthCounters++;
  if (depthCounters>maxMissile) {
   depthCounters = 10;
  }
 }
 if (Key.isDown(Key.RIGHT)) {
  if (this._x<scrollx) {
   this._x += moveSpeed;
  } else {
   scrollStart = true;
  }
 } else if (Key.isDown(Key.LEFT) and this._x>30) {
  this._x -= moveSpeed;
 }
 if (Key.isDown(Key.DOWN) and this._y<280) {
  this._y += moveSpeed;
 } else if (Key.isDown(Key.UP) and this._y>15) {
  this._y -= moveSpeed;
 }
}
onClipEvent (keyUp) {
 if (Key.getCode() == Key.RIGHT) {
  scrollStart = false;
 }
}

```

this is the code on the laser:

```auto
onClipEvent (load) {
 laserMoveSpeed = 20;
 this._x = _root.spaceship._x-15;
 this._y = _root.spaceship._y+31;
}
onClipEvent (enterFrame) {
 if (this._name<>"laser") {
  this._x += laserMoveSpeed;
  if (this._x>750) {
   _root.spaceship.laserCounter--;
   this.removeMovieClip();
  }
  for (i=1; i<=_root.numEnemy; i++) {
   if (this.hitTest(_root["enemy"+i]) and _root["enemy"+i].hitFlag == false) {
    _root.score += 100;
    _root.spaceship.enemie **** ++;
    if (_root.spaceship.enemie **** >=20) {
     _root.spaceship.enemie **** = 0;
     _root.newLevel();
    }
    _root["enemy"+i].hitFlag = true;
    _root["enemy"+i].gotoAndPlay(2);
   }
  }
 }
}

```

this is the code on the star:  
NOTE: the movie is 700x350 resolution running at 20fps.

```auto
onClipEvent (load) {
ground.duplicateMovieClip("ground2", 100);
ground2._x = ground._x+ground._width;
groundStartx = this._x;
groundSpeed=15;
}
onClipEvent (enterFrame) {
if (_root.spaceship.scrollStart){
 this._x-=groundSpeed;
 if (this._x<= (groundStartx-ground._width)){
  this._x=groundStartx-groundSpeed;
 }
}
}

```

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 5, 2004, 7:45am UTC](https://forum.kirupa.com/t/problem-duplicating-a-scrolling-mc-and-removing-laser/56276/2 "2004-07-05T07:45:02Z")

</div>

can anyone please help me out if u need the fla let me know anyone

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 5, 2004, 8:30am UTC](https://forum.kirupa.com/t/problem-duplicating-a-scrolling-mc-and-removing-laser/56276/3 "2004-07-05T08:30:20Z")

</div>

post the fla and I’ll have a look :¬)

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 6, 2004, 5:44am UTC](https://forum.kirupa.com/t/problem-duplicating-a-scrolling-mc-and-removing-laser/56276/4 "2004-07-06T05:44:57Z")

</div>

> [@tommythewolfboy](#):
>
> post the fla and I’ll have a look :¬)

hey man thanks for the help cuse so far no body at all has been able to find a solution and i am not good at all with AS heres the file

[http://www.geocities.com/mixedtrigenito/Eros.fla](http://www.geocities.com/mixedtrigenito/Eros.fla)

[http://www.geocities.com/mixedtrigenito/Eros.fla](http://www.geocities.com/mixedtrigenito/Eros.fla)

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 9, 2004, 10:02am UTC](https://forum.kirupa.com/t/problem-duplicating-a-scrolling-mc-and-removing-laser/56276/5 "2004-07-09T10:02:31Z")

</div>

Sorry - been a really busy week and haven’t had a chance to look at it yet. If you can hang on until next week, I’ll have a look then unless someone else can help you in the meantime. Couple of points from quickly looking at it though:  
(1) you can only use removeMovieClip(); if the clip was created using duplicateMovieClip. I can’t remember from the file, but I don’t think this was how you created it … Instead, as part of the hit test A/S, simply reset the \_x and \_y of the laser and make it invisible after it hits an enemy, e.g.  
this.\_x = \_root.spaceship.\_x-15;  
this.\_y = \_root.spaceship.\_y+31;  
this.\_visible = false;

(2)With respect to respawning the ground, I had a brief look at the file and I don’t understand why you are doing it the way you’ve chosen. You could simply make the clip.\_x the original value once it has gone off the edge of the screen? Search the threads for ‘continuous scrolling’ as there’s plenty here already. My only word of warning is that you’ll need to check the registration point of the star clip (as this is the \_x value used) which may not necessarily be what you are expecting it to be in relation to the main stage - especially since it is embedded inside a blank movieclip, so the \_x actually refers to it’s position inside that clip, not the \_x in relation to the \_root. Hope that makes sense!  
Tell me how you get on, and as I said, I can always have a better look next week.

t

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 9, 2004, 2:11pm UTC](https://forum.kirupa.com/t/problem-duplicating-a-scrolling-mc-and-removing-laser/56276/6 "2004-07-09T14:11:05Z")

</div>

Ok, I’ve done some fixes… I don’t doubt there is still many other ways to improve it, but that’s the fun for you.🙂

[try either of these, rar is smaller]

[http://hosting.mixcat.com/dinnerdog/Eros\_DD.rar](http://hosting.mixcat.com/dinnerdog/Eros_DD.rar)  
[http://hosting.mixcat.com/dinnerdog/Eros\_DD.zip](http://hosting.mixcat.com/dinnerdog/Eros_DD.zip)

any problems just reply.  
good luck

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 10, 2004, 5:02am UTC](https://forum.kirupa.com/t/problem-duplicating-a-scrolling-mc-and-removing-laser/56276/7 "2004-07-10T05:02:32Z")

</div>

> [@dinner dog](#):
>
> Ok, I’ve done some fixes… I don’t doubt there is still many other ways to improve it, but that’s the fun for you.🙂
> 
> [try either of these, rar is smaller]
> 
> [http://hosting.mixcat.com/dinnerdog/Eros\_DD.rar](http://hosting.mixcat.com/dinnerdog/Eros_DD.rar)  
> [http://hosting.mixcat.com/dinnerdog/Eros\_DD.zip](http://hosting.mixcat.com/dinnerdog/Eros_DD.zip)
> 
> any problems just reply.  
> good luck

wow man thanks a lot for everything i really appreciated it. and by the way what do you think about the game? even though is not much cuse is my first game with flash. and i just wanted to take it for a test drive.
