I'm using the Sparrow framework (V2) and I'm having a very strange issue which might be something to do with Sparrow or it might be something to do with Obj-c. I'm using ARC for the project.
I'm creating a movieclip which is a dice animation, I'm then adding an listener to it and using the block to remove the animation and movieclip, like this..
diceAnimationPlayer1 = [self getAnimation:atlasName1 fName:frameName1 nFrames:12];
__weak SPMovieClip *weakMC = diceAnimationPlayer1;
__weak SPSprite *weakSP = villageSprite;
[diceAnimationPlayer1 addEventListenerForType:SP_EVENT_TYPE_COMPLETED block:^(SPEvent *event)
{
[Sparrow.juggler removeObject:weakMC];
[weakSP removeChild:weakMC];
}];
That all works fine. The problem comes if I don't want to delete the movieclip at that point but want to remove diceAnimationPlayer1 at a later date, say after another animation has finished. If I try to do
[villageSprite removeChild:diceAnimationPlayer1];
Not only does it not remove the movieclip but it changes the movieclip to a new Atlas! (I have 6 dice atlases, one for each side), so the dice changes to a new number on the final frame.
I've checked to see if I'm creating one movieclip over the top of another, maybe there's 2 there, but as far as I can see I'm not, it's very odd.
Does anyone have any idea what could cause this? I don't quite understand all this weak business anyway, is the weak reference somehow creating a completely new object? (even though inspecting the variables in debug seems to show them all pointing at the same thing).
Also adding to the answer below (which unfortunately doesn't solve the issue) ,why doesn't this remove the object?
diceAnimationPlayer1 = [self getAnimation:atlasName1 fName:frameName1 nFrames:12];
__weak __block SPMovieClip *weakMC = diceAnimationPlayer1;
__weak __block SPSprite *weakSP = villageSprite;
[diceAnimationPlayer1 addEventListenerForType:SP_EVENT_TYPE_COMPLETED block:^(SPEvent *event)
{
[Sparrow.juggler removeObject:weakMC];
[villageSprite removeChild:diceAnimationPlayer1];
//[weakSP removeChild:weakMC];
}];
I get the same result, the dice animation is not removed, and it just switches to another atlas showing a different final number.
By default when you referencing referenc type object inside your block it is retained, to prevent retain you need to mark it as __block. Try the following way