A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: removeMovieClip(); not working in tile based game...

  1. #1
    Robot Master the--flash's Avatar
    Join Date
    Jul 2005
    Location
    The year 20XX...
    Posts
    132

    removeMovieClip(); not working in tile based game...

    removeMovieClip no work!

    That pretty much sums up my last half an hour. I've been working on a game which is basically a bunch of TonyPa's tutorials put together (wanted to expand on them...) and today I decided to try and put firepower into the mix, allowing my character, Mario, to shoot fire. I put the code in, made it work with what I have, but for some mind boggeling reason I can't get rid of the fireballs. This isn't some sort of coding mishap, because everything else in the if statement works fine. It just won't go away!

    Here's what I have...

    Code:
    for (var i = 0; i<game.bullets.length; ++i) {
        var ob=game.bullets[i];
        getMyCorners (ob.x+ob.speed*ob.dirx, ob.y+ob.speed*ob.diry, ob);
        if (game[ob.upleft].walkable and game[ob.upright].walkable) {
        	if (!game[ob.downleft].walkable and !game[ob.downright].walkable) {
    	  		ob.diry *= -1;
    		} else {
    			moveChar(ob, ob.dirx, ob.diry);
    		}
        } else {    
    	  ob.clip.removeMovieClip();
          delete game["bullet"+game.bullets[i].id];
          game.bullets.splice(i,1);
    	  
        }
    The code loops through all the bullets in the game.bullets array, sets the variable "ob" to the bullet, then checks for collision. Everything works just fine! The actual bullet is deleted (I think) but it won't go away! If I put in
    Code:
    ob.clip._visible = false;
    it does disappear! Seems only that slippery removeMovieClip(); isn't working...

    I've put the .fla in the bottem, because this problem is really boggeling me. I havn't done much flash for awhile, so there might (probably) be something I'm missing. Thanks for all the help.

    EDIT: Hmm, for some reason my file is 440 KB, and it's too big. Guess you'll have to imagine what it looks like for now
    Last edited by the--flash; 08-14-2008 at 10:55 PM.

  2. #2
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    really need that fla, is there somewhere you can upload it to for free?

    clicked on the first link in google: http://www.4shared.com/

    it all looks fine to me, if all else fails, trace out (ob.clip), (typeof ob.clip) if its a movieclip then ob.clip.removeMovieClip() should work. Or AS2's super magic function is flawed.

    this:

    delete game["bullet"+game.bullets[i].id];

    could be just:

    delete game["bullet" + ob.id];
    lather yourself up with soap - soap arcade

  3. #3
    Robot Master the--flash's Avatar
    Join Date
    Jul 2005
    Location
    The year 20XX...
    Posts
    132
    Yeah, I can see how this would be tough to help without the .fla, so I put it up on filefront.

    http://files.filefront.com/TileBased.../fileinfo.html

    Also, I'm pretty sure delete game["bullet"+game.bullets[i].id]; is working, since if I shoot the fireballs at the ground and they walk over them, they don't die...

  4. #4
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    your problem is this:

    game.clip.attachMovie("bullet",name,10100000+game. bulletcounter);

    the depth is too high, take out 10100000. Once a movieclip goes above a certain depth or below 0 it cannot be removed using code. AS2 rocks!

    Its best to put bullets inside a different parent movieclip. so:

    game.bullets.attachMovie("bullet", name, game.bulletcounter);

    that way, you know that only bullets are in that movieclip.
    lather yourself up with soap - soap arcade

  5. #5
    Robot Master the--flash's Avatar
    Join Date
    Jul 2005
    Location
    The year 20XX...
    Posts
    132
    Alright, worked just fine, thanks very much!

  6. #6
    Senior Member Gohloum's Avatar
    Join Date
    Aug 2002
    Location
    Florida
    Posts
    185
    Quote Originally Posted by mr_malee
    your problem is this:

    game.clip.attachMovie("bullet",name,10100000+game. bulletcounter);

    the depth is too high, take out 10100000. Once a movieclip goes above a certain depth or below 0 it cannot be removed using code. AS2 rocks!

    Its best to put bullets inside a different parent movieclip. so:

    game.bullets.attachMovie("bullet", name, game.bulletcounter);

    that way, you know that only bullets are in that movieclip.

    Nice call Malee. For everyone who reads this, if you are having a problem with removeMovieClip(), you can bet it's an issue dealing with depth. If your file uses swapDepth() and you accidentally swap 2 items to the same depth in the same cycle, then reference is lost to one of them and you won't be able to get to it.
    The Early Bird may get the worm, but the second mouse to the trap gets the cheese...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center