How to communicate between loaded swf and parent swf

Hi guys,

I started learning the basics of as3.0 a year ago by doing a lot of experiments… I never read a book or took lessons or something… I guess i’m still missing important logics when i’m programming. I’m creating my personal flash imagegallery but I can’t figure out how to communicate between a loaded swf and its parent swf.

This is my problem:
I have a main.swf file with document class main.as which loads external swf files into a movie container. I am also loading a background sound like:


public class Main extends MovieClip {
     private var bgMusic:BackgroundMusic;
     ....
     public function Main():void {
         bgMusic = new BackgroundMusic();
         ....
     }
}

The BackgroundMusic class loads the actual mp3 file and starts playing it. I have also created two public methods StopMusic() and StartMusic(). Main.as also creates a button to stop and play the sound which is working great.


public class BackgroundMusic extends MovieClip {
...
        public function StopMusic():void {
            // stops sound...
        }
        
        public function StartMusic():void {
            // starts sound...
        }
}

To stop the sound with the button in main.swf I do this:


private function StatusButtonDownHandler(event:MouseEvent):void {
    switch (event.target.shortname) {
        case "music" :
            if(bgMusic.isPlaying) {
                bgMusic.StopMusic();
                DisableStatusButton(event.target);
            } else {
                bgMusic.StartMusic();
                EnableStatusButton(event.target);
            }

I’m loading my ImageGallery.swf into a movieclip called swfContainer. The imagegallery document class does what a regular gallery does and that is displaying images that are loaded from an xml file. When an image is clicked I’m creating a SlideShow instance (SlideShow.as). The slideshow hides everything and shows the image with a status bar that has navigation buttons and some other stuff like change background color, show fullscreen, optimize image for faster loading etc…
Now I also want to have a background sound button so I can stop/play the sound I have loaded from the main.swf file.

To Communicate between two classes I read a lot about firing events and that is what I’m using a lot… like when an image is fully loaded an event is fired telling the parent class to do a spefic action… in my case that would be some curtain effect that opens to make the image visible.

But how can I tell main.swf to stop the background sound when I click the button in the loaded swf? First of all when I am testing my ImageGallery.swf, pressing Ctrl+Enter inside Flash, the main.swf is never started… I have to select main.swf in the document tabs and hit Ctrl+Enter… confusing but also logical…

The only work around I was thinking about would be to keep showing the stop/start sound button from the main.swf when a slideshow instance is called… but then I’ll screw up my design :frowning: I want a second button inside the slideshow that can also stop the main bg sound…

Looks to me this is a basic question but I really don’t have a clue!
I would appreciate if someone could tell me or maybe show me an example how to handle this?

Thanks a lot!! This problem is chasing me more than a month! :crying: