0

Hey everyone so I have a Movie clip named mTriangle and It's added to the stage like so:

        mTriangle = new mcTriangle();
        stage.addChild(mTriangle);
        mTriangle.x = (stage.stageWidth / 2);
        mTriangle.y = (stage.stageHeight / 2);

Now inside this Movie Clip I have a sound that plays on certain frames in the tween. The sound isn't referenced to anything it's just their and only plays on certain frames.

Now in my endGameFunction(); I remove the MovieClip like so:

mTriangle.destroyTriangle();

the destroyTriangle function is located in my mTriangle class like so:

public function destroyTriangle():void
{
    if (this.parent)
    {
        parent.removeChild(this);
        trace("REMOVED");
    }
}

Now it removes the MovieClip just fine but the sound still plays afterwards. I don't know how to end the sound as well. I tried to add **mTriangle = null;** for GC but still nothing and I end up getting an error of null reference. Does anyone have any suggestions? I would add the sound through code inside the mTriangle class but i don't know exactly how since i want the sound to play on, for instance frame 5, 9, 10;

Sushil
  • 8,250
  • 3
  • 39
  • 71
Nathan
  • 536
  • 4
  • 21
  • How about calling the stop() method on that MovieClip, the sound should stop as well. Then remove it and set to null if you want. Setting to null is not necessary – Creative Magic Mar 07 '14 at 08:25
  • But if I don't set it up to null wont it consume memory and make the game lose fps over a period of time when a new instance of the movie clip is added when the user restarts the game? – Nathan Mar 07 '14 at 08:34
  • 1
    it will not really instantly remove it when you make it a null. The object will be removed by GC anyway IF: there are no references to in in arrays, no strong event listeners attached, it's not on display list. You may want to set it to null only if it's a class variable and the class instance itself is not removed. – Creative Magic Mar 07 '14 at 08:38
  • Did my first comment help you to stop the sound in your MovieClip? – Creative Magic Mar 07 '14 at 09:13
  • It's well know problem MovieClip + Sound. Sound will play until MovieClip is garbage collected. About your question with 5,9, 10 frame, do you want the same Sound, or different Sounds? How long are sounds in triangle? – Nicolas Siver Mar 07 '14 at 10:00

0 Answers0