Forum Topic: removeMovieClip is Being Rude

(406 views • 21 replies)

This topic is 1 page long.

<< < > >>
Crying

jmtb02

Reply To Post Reply & Quote

Posted at: 1/4/08 02:02 PM

jmtb02 LIGHT LEVEL 29

Sign-Up: 03/01/04

Posts: 5,844

Why does removeMovieClip() freeze when I try to remove a movieClip? The movieClip is at negative depth because it was preplaced on the stage, so I am using swapDepths to give it a new depth.

if(hole.hitTest(mov)) {
mov.swapDepths(k++);
trace(mov.getDepth()); // traces 135
mov.removeMovieClip(); //freezes movie, as if an infinite while loop is running
}

That's it! I can run the code without the mov.removeMovieClip() without error, but suddenly Flash is frowntown with the whole removeMovieClip thing. Any pro tips? I tried using a different depth changing method (_root.getNextHighestDepth()), but it's all coming down.

Hi there!

BBS Signature

None

Drkgodz

Reply To Post Reply & Quote

Posted at: 1/4/08 02:03 PM

Drkgodz DARK LEVEL 09

Sign-Up: 08/26/06

Posts: 30

What does k have inside it?


None

jmtb02

Reply To Post Reply & Quote

Posted at: 1/4/08 02:05 PM

jmtb02 LIGHT LEVEL 29

Sign-Up: 03/01/04

Posts: 5,844

At 1/4/08 02:03 PM, Drkgodz wrote: What does k have inside it?

k is an incrementing variable, similar to getNextHighestDepth() except working as it's own variable. I use k because I like to have more control over my depths. But I can replace that k with getNextHighestDepth() to the same result.

Hi there!

BBS Signature

None

Paranoia

Reply To Post Reply & Quote

Posted at: 1/4/08 02:08 PM

Paranoia DARK LEVEL 34

Sign-Up: 04/22/05

Posts: 9,697

At 1/4/08 02:02 PM, jmtb02 wrote: That's it! I can run the code without the mov.removeMovieClip() without error, but suddenly Flash is frowntown with the whole removeMovieClip thing. Any pro tips? I tried using a different depth changing method (_root.getNextHighestDepth()), but it's all coming down.

Is there a loop or recursive function somewhere else which might require mov to exist to work properly?

BBS Signature

None

ShirkDeio

Reply To Post Reply & Quote

Posted at: 1/4/08 02:15 PM

ShirkDeio LIGHT LEVEL 16

Sign-Up: 03/29/07

Posts: 989

At 1/4/08 02:02 PM, jmtb02 wrote: Why does removeMovieClip() freeze when I try to remove a movieClip? The movieClip is at negative depth because it was preplaced on the stage, so I am using swapDepths to give it a new depth.

if(hole.hitTest(mov)) {
mov.swapDepths(k++);
trace(mov.getDepth()); // traces 135
mov.removeMovieClip(); //freezes movie, as if an infinite while loop is running
}

That's it! I can run the code without the mov.removeMovieClip() without error, but suddenly Flash is frowntown with the whole removeMovieClip thing. Any pro tips? I tried using a different depth changing method (_root.getNextHighestDepth()), but it's all coming down.

Hmm. The inside code works fine for me--try replacing the block of code with a trace function and see if it still freezes. Also, I prefer to use "removeMovieClip(mov)" instead of "mov.removeMovieClip()"

I am a servant of the Most High God
The Hanging Collab || The Legend of Newgrounds (Game) || Crystal Rays (Song)


None

jmtb02

Reply To Post Reply & Quote

Posted at: 1/4/08 02:17 PM

jmtb02 LIGHT LEVEL 29

Sign-Up: 03/01/04

Posts: 5,844

At 1/4/08 02:08 PM, Paranoia wrote: Is there a loop or recursive function somewhere else which might require mov to exist to work properly?

The while loops are nested in conditionals that require the clip to exist in order for them to function, and occur before the removeMovieClip function occurs.

if (hole.hitTest(mov._x, mov._y, true) && mov.xTravel != 0) {
while(//blah) {
}
}

HitTest can't work on a clip that is removed, correct?

Hi there!

BBS Signature

None

ShirkDeio

Reply To Post Reply & Quote

Posted at: 1/4/08 02:19 PM

ShirkDeio LIGHT LEVEL 16

Sign-Up: 03/29/07

Posts: 989

At 1/4/08 02:17 PM, jmtb02 wrote:
At 1/4/08 02:08 PM, Paranoia wrote: Is there a loop or recursive function somewhere else which might require mov to exist to work properly?
The while loops are nested in conditionals that require the clip to exist in order for them to function, and occur before the removeMovieClip function occurs.

if (hole.hitTest(mov._x, mov._y, true) && mov.xTravel != 0) {
while(//blah) {
}
}

HitTest can't work on a clip that is removed, correct?

It shouldn't work on a removed clip, but it may still be reading it. Try saying "mov._x = -9999" and see if it still glitches. That would tell you if hittest is still tracking the old position of the clip.

I am a servant of the Most High God
The Hanging Collab || The Legend of Newgrounds (Game) || Crystal Rays (Song)


None

CybexALT

Reply To Post Reply & Quote

Posted at: 1/4/08 02:23 PM

CybexALT NEUTRAL LEVEL 02

Sign-Up: 10/13/05

Posts: 345

Try using mov.unLoadMovie() instead. see if that works.


None

GuyWithHisComp

Reply To Post Reply & Quote

Posted at: 1/4/08 02:23 PM

GuyWithHisComp LIGHT LEVEL 27

Sign-Up: 11/10/05

Posts: 4,008

Still uisng ActionScript 2 are we? tttt...
Also, what happens if you trace mov._x and mov._y right after it's removed? Does it output the x and y values. Maybe they're still there (you never know with as2)

Also, I don't know if you want it to break there but try breaking the while loop right after you remove the clip,

break;
BBS Signature

None

jmtb02

Reply To Post Reply & Quote

Posted at: 1/4/08 02:25 PM

jmtb02 LIGHT LEVEL 29

Sign-Up: 03/01/04

Posts: 5,844

At 1/4/08 02:19 PM, ShirkDeio wrote: It shouldn't work on a removed clip, but it may still be reading it. Try saying "mov._x = -9999" and see if it still glitches. That would tell you if hittest is still tracking the old position of the clip.

I have completely removed the while and for loops from the entire movie, and the same error occurs.

I have also tried executing the code on different frames, to different results. On some frames, the removeMovieClip executes correctly. However, the code is the same code just on different frames of the movie! I'm guessing at this point it's just a Flash error.

Hi there!

BBS Signature

None

UnknownFury

Reply To Post Reply & Quote

Posted at: 1/4/08 02:25 PM

UnknownFury EVIL LEVEL 26

Sign-Up: 08/10/05

Posts: 6,027

Isn't quite the same but maybe try mov.unloadMovie(); instead and just see what happens.

Portfolio(Under construction): UnknownFury.com |
Msn: giant_ak_47@msn.com | Contact: me@unknownfury.com
Follow me on twitter!


None

Kart-Man

Reply To Post Reply & Quote

Posted at: 1/4/08 02:28 PM

Kart-Man NEUTRAL LEVEL 27

Sign-Up: 01/07/07

Posts: 3,731

At 1/4/08 02:25 PM, jmtb02 wrote:
At 1/4/08 02:19 PM, ShirkDeio wrote: It shouldn't work on a removed clip, but it may still be reading it. Try saying "mov._x = -9999" and see if it still glitches. That would tell you if hittest is still tracking the old position of the clip.
I have completely removed the while and for loops from the entire movie, and the same error occurs.

I have also tried executing the code on different frames, to different results. On some frames, the removeMovieClip executes correctly. However, the code is the same code just on different frames of the movie! I'm guessing at this point it's just a Flash error.

Just to be sure, try executing the code in a different Flash document (copy, paste). Sometimes, code magically works when you do that. :/


None

Paranoia

Reply To Post Reply & Quote

Posted at: 1/4/08 02:29 PM

Paranoia DARK LEVEL 34

Sign-Up: 04/22/05

Posts: 9,697

At 1/4/08 02:17 PM, jmtb02 wrote: HitTest can't work on a clip that is removed, correct?

It shouldn't be a problem anyway - if a clip in the condition doesn't exist then it'll just return false and abort the loop.

Anyway, since I'm using AS3 this is the sort of thing which would throw a compile error - you can't access a property or method on a null object reference. I know you're using AS2 here, but just see if putting:

if(mov != null){ ...

Before any code you need mov for does anything.

BBS Signature

None

jmtb02

Reply To Post Reply & Quote

Posted at: 1/4/08 02:30 PM

jmtb02 LIGHT LEVEL 29

Sign-Up: 03/01/04

Posts: 5,844

At 1/4/08 02:23 PM, CybexALT wrote: Try using mov.unLoadMovie() instead. see if that works.

It unloads the contents of the movieClip but the clip is still coming up as existent.

Hi there!

BBS Signature

None

gankro

Reply To Post Reply & Quote

Posted at: 1/4/08 02:32 PM

gankro EVIL LEVEL 11

Sign-Up: 09/16/06

Posts: 1,173

try temporarily star quoting all your loops if removeMovieClip(); works then unquote one after another to try and find the problem loop.

My Coding Portfolio (updated frequently)
If you stay in bed for long enough it will be socially acceptable to go to bed again

BBS Signature

None

jmtb02

Reply To Post Reply & Quote

Posted at: 1/4/08 02:36 PM

jmtb02 LIGHT LEVEL 29

Sign-Up: 03/01/04

Posts: 5,844

Alright, thanks guys for all your help, but I have come to the conclusion that the proper fix is either:

_root.removeMovieClip();

or

mov._visible = false;

And I am voting for the latter... the clip isn't really processor intensive and its just causing me headaches. Thanks for your help, you guys were pretty creative for finding fixes.

Hi there!

BBS Signature

None

CybexALT

Reply To Post Reply & Quote

Posted at: 1/4/08 02:42 PM

CybexALT NEUTRAL LEVEL 02

Sign-Up: 10/13/05

Posts: 345

Whats the condition of the while loop, what code is inside it. Is there any code that will upset the while loop if mov no longer sxists.

Also, this sounds kind of stupid, but try putting mov._x=999999 just so that its no longer hitting the other object when it is removed.


None

GustTheASGuy

Reply To Post Reply & Quote

Posted at: 1/4/08 02:43 PM

GustTheASGuy LIGHT LEVEL 08

Sign-Up: 11/02/05

Posts: 11,427

createEmptyMovieClip ('', mov.getDepth ()) ?

#ngprogramming at irc.freenode.net
haXe | Keel imperative | Spyro! | Thru you


None

Arby

Reply To Post Reply & Quote

Posted at: 1/4/08 03:26 PM

Arby LIGHT LEVEL 26

Sign-Up: 10/24/04

Posts: 2,234

Perhaps it's time to move up to AS3? =P

<3 addChild() and removeChild()

You can begin by joining the AS war thats floating about =P

At first there was nothing, then it exploded. - Big bang


None

jmtb02

Reply To Post Reply & Quote

Posted at: 1/4/08 04:45 PM

jmtb02 LIGHT LEVEL 29

Sign-Up: 03/01/04

Posts: 5,844

At 1/4/08 03:26 PM, Arby wrote: Perhaps it's time to move up to AS3? =P

Cmon, I JUST moved up from AS1. Let's be gentle now.

Hi there!

BBS Signature

None

UnknownFury

Reply To Post Reply & Quote

Posted at: 1/4/08 04:47 PM

UnknownFury EVIL LEVEL 26

Sign-Up: 08/10/05

Posts: 6,027

At 1/4/08 03:26 PM, Arby wrote: Perhaps it's time to move up to AS3? =P

<3 addChild() and removeChild()

You can begin by joining the AS war thats floating about =P

I'm still on AS2 also >:)

Portfolio(Under construction): UnknownFury.com |
Msn: giant_ak_47@msn.com | Contact: me@unknownfury.com
Follow me on twitter!


The-Super-Flash-Bros LIGHT LEVEL 27

Sign-Up: 09/02/02

Posts: 1,247

At 1/4/08 02:43 PM, GustTheASGuy wrote: createEmptyMovieClip ("'', mov.getDepth ()) ?

Thats the one I used, removeMovieClip used to cause all sorts of issues for me. Works like a charm

Tom-


All times are Eastern Standard Time (GMT -5) | Current Time: 09:26 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!