maybe I am just thinking out loud (and my mind is a tricky one)
but, don't you delete an object's instances and not directly the class
itself (how could it delete itself ?) ?
like:
var baddieInstance = new Baddie();
... later ...
baddieInstance.die(); // internal deletion process (like
removeListener ,....)
delete(baddieInstance); // instance deletion
??
Cedric
Nice one - thanks Andreas. :o)
Andreas Rønning wrote:
Mark Burvill wrote:
Hi all,
I've just started transitioning to AS2 (so go easy on me), and have
a question about a game I'm building...
I have a "Baddie" object which handles a baddie on the screen, and
when one gets killed, and has finished it's death animation, I'm
running a method within the Baddie object called die() which deletes
the associated movieClip, and then is meant to delete the baddie
Object itself, but it doesn't seem to work....
public function die():Void {
trace ("deleting");
removeMovieClip (baddie_mc);
delete this;
trace ("Am i still alive?");
}
The movieclip is successfully removed, but I would expect the second
trace "Am I still alive" NOT to appear as the object has been
deleted, but it does.
I read somewhere that it is illegal for an object to delete itself -
is this true?
Is there another easy way of doing this?
Thanks! :o)
Mark
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
No sir, objects do not delete themselves. For my projects i have an
external destructor function, for instance:
//enemy class
class Enemy{
private var creator:Object;
private var myClip:MovieClip;
public function Enemy(c:Object){
creator = c;
}
public function death():Void{
playSound(explosion); //for instance
removeMovieClip(myClip);
}
public function destroy():Void{
creator.destroyEnemy(this);
}
}
//whatever deploys the enemies
var enemies:Array;
function addEnemy(){
enemies.push(new Enemy());
}
function destroyEnemy(e:Enemy){
for(var i = enemies.length;i--;){
if(enemies[i]==e){
enemies[i].death();
enemies.splice(i,1);
break;
}
}
}
Didnt give this much thought so its probably not brilliant, but you
get the idea
- A
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
--
*Mark Burvill*
Interactive designer
www.eyegas.com <http://www.eyegas.com>
*Work:* 0117 953 0100
*Mobile*: 07780 608498
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders