View Full Version : Removing MovieClips
Lou
November 15th, 2006, 12:10 AM
Hello all!
I wanted to know if there was a way to remove a movieclip using code from within the clip itself. In other words, I want the clip to remove itself. Im making a game where you abduct people, so when the human reaches the same height of your ship, he is removed. I have humans spawning randomly so I cant keep track of their specific MC names.
Well I guess I could make him respawn when he reaches the ship... :cross-eye
... but for future refrence does anyone know how?
habes
November 15th, 2006, 12:15 AM
have a loop for the humans that uses this.removeMovieClip(); when it reaches a certain height. at least thats what i would do.
Lou
November 15th, 2006, 12:40 AM
I think you're onto something, but it did not work.
if (this._y < _root.UFO._y) {this.removeMovieClip();}
habes
November 15th, 2006, 01:06 AM
first off, make sure your attaching the people with actionscript (i.e. attachMovie,duplicateMovie)
onClipEvent(enterFrame){
or
person.onEnterFrame=function(){
if(this._y<_root.UFO._y){
this.removeMovieClip();
}
}
you could also apply a for loop. make each person have an instance name of person+(number),ex: person1, person2 etc, and put this on a enterframe:
for(p=1;p<=(create a variable = to number of people and put here);p++){
var personLoop="person"+p
personLoop.onEnterFrame=function(){
if(this._y<_root.UFO._y){
this.removeMovieClip();
}
}
}
this would make it so you dont have to keep putting the code onto each person
i hope thats clear and what you looking for
Lou
November 15th, 2006, 01:25 AM
Well my programming logic consists of nested ' if ' statements. Right now my code is all over the place like diarrhea. I think the remove clip line is just in the wrong spot. I will wade back through the code and sort it out. Thanks for the help.
habes
November 15th, 2006, 02:28 AM
Maybe this will help, good luck (fla attached)
Thinker2501
November 15th, 2006, 06:42 PM
Your code should exist all in the main time-line and in separate class files, that prevents this exact sort of confusion. The this.removeMovieClip(); command will remove a movieClip placed on the state with actionscript when that command is executed inside the attached movieClip.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.