A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: delete sprite -- or remove instance from stage

  1. #1
    Senior Member
    Join Date
    Jun 2003
    Location
    La Mirada California
    Posts
    396

    delete sprite -- or remove instance from stage

    I often create a function disengage() and call it when I want a certain component to leave the stage. Usually in the function I make the MC/Sprite's x=-100000; or something just so it's not visible, and doesn't obstruct anything else on the stage.

    Now I was thinking instead just to delete that Sprite, and create it when I want to see it again. Is that a good idea?

    If so, when I use delete.this in the class instance, I get no errors, but it doesn't remove the class instance (which is a sprite, with a bunch of children--Textfields, & shapes).

    What's the best way to do this?

  2. #2
    Junior Member
    Join Date
    Oct 2008
    Posts
    26
    if you know the index of your sprite you can call a function in your displayobject container and use the removeChildAt(index) method. you can find your sprites index by the method getChildIndex(mydsp:displayobject). another way to do it is to just remove the variable directly using removeChild() method. ie.... var mySprite:Sprite = new Sprite, you could use removeChild(mySprite). I'm sure there are even more ways to do it as well

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