Where to place destroy() in script?

Hi guyz,
I’m new to Action Script (new to Flash actually) and getting stuck at what may be a very simple question…

The situation is this:
I’m working on a AS2 website (template, exporting to Flash 8) that is 100% xml loaded Flash. So the main movie has a menu with mainmenu items (“mmitems”) and submenu items (“smitems”) that are generated using an xml file.
When you click a menu item an external module (gallery, slideshow, etc) is loaded into a container.
Now, I want to load an external module that is a YouTube video player. The loading works perfectly and the player works fine.

The problem is unloading it:
when I click another menu item, the YouTube player is removed from stage as it should be, but the audio keeps playing. I know I’m supposed to use the (loader name).ytplayer.destroy() code somewhere, but I’ve no idea where and in which script exactly to place this!

In the main movie, nothing is done on the timeline and all the script is on the first and second frame. So I have the following levels:

  • actionscript (frame 1 and 2, all the script))
  • mainmenubuttons (frame 1 and 2, no script, instance “navig” on frame 2)
  • submenubuttons (frame 1 and 2, no script, instance “subnavig” on frame 2)
  • content (frame 1 and 2, no script, instance “moduleloader” on frame 2)

Then there is the YouTube videoplayer itself. All the scripting is on frame 1 of the first level, so aside from the levels holding the controlbuttons and so on I have:

  • as (frame 1, all the script)
  • ytplayer (frame 1, instance “ytplayer”)

As far as I can understand, the destroy-script destroys the instance of “ytplayer” so it breaks the connection with YouTube and stops loading the videoclips. I also understand that this has to be done before the next menu item in the main movie is clicked to load the next module. But that still doesn’t tell me where to actually put that line of script.

Hope you can help as I’ve been stuck on this for ages now… :frowning:

TIA!