Skip to main content
Known Participant
January 9, 2008
Question

add/remove child - Programming Practices

  • January 9, 2008
  • 3 replies
  • 340 views
Greetings All,

I have a general question in terms of actionscript programming, and movie clips on stage.

I have an application that can add (or remove) children to the stage (or from the stage).
When I click a button I want to run a tween that moves an object on the stage.
When I click that same button again - I no longer want to run the tween, but allow some other action on the stage.

I have two movie clips associated with this process (not counting background object, etc).
One clip moves with the tween and its settings, the other just appears on the stage over the other objects.

I can addChild/removeChild for these clips, alternating as required, or add all the children to the stage, and either do a get/set Childindex kind of thing, or visible true/false kind of thing. I would also like to consider removing the tween.
Is there a way to remove a tween (after "adding" it using the var myTween:Tween = new Tween()).

My question is what would a good actionscript programmer do in this circumstance??

Thanks for a good forum here.

eholz1
This topic has been closed for replies.

3 replies

eholz1Author
Known Participant
January 10, 2008
Hello NTBDY,

That does help. Thanks,

eholz1
eholz1Author
Known Participant
January 10, 2008
Hello NTBDY,

That does help. Thanks,

eholz1
Inspiring
January 10, 2008
quote:

Originally posted by: eholz1
I can addChild/removeChild for these clips, alternating as required, or add all the children to the stage, and either do a get/set Childindex kind of thing, or visible true/false kind of thing. I would also like to consider removing the tween.
Is there a way to remove a tween (after "adding" it using the var myTween:Tween = new Tween()).

My question is what would a good actionscript programmer do in this circumstance??


I believe I understand what you want to do. You want to clean up, so to speak. Which is good, because you'll be freeing up resources, such as memory.

So, you'd want to dereference the Tween object that you've created.

myTween = null;

with no reference to your object, it will eventually be garbage collected

I'd also have removed any registered listeners beforehand

Hope that helps.