Hi,
I need to play SWF files in my project. These SWF files have background music in them. The which Sound Sync Options of this music in Flash is set to "stream". This is done so that if you pause the Flash movie, the music will pause as well.
Now I have a problem when I am loading these SWF files. For this I am using an SWFLoader.
When I load it, the audio of the SWF starts playing already, but no visuals of the movie are shown for a certain time. The slower your connection is, the longer it takes before visuals of the movie is shown. The audio and visuals are in sync, that is good, however, the first frames of the flash movie are simply not displayed.
I tried to solve this by adding an eventListener to make sure that the movie is fully loaded before it starts to play. However, when I do this (code below), for a fraction of a second the music plays, then stops, and restarts when the movie is fully loaded.
What is the best way to solve this problem? Am I on the right track with the ProgressEvent.PROGRESS eventlistener?
Some code:
private function loadSWF():void
{
swfLoader.source = source;
swfLoader.addEventListener(ProgressEvent.PROGRESS, loadProgress);
swfLoader.addEventListener(Event.COMPLETE, startSWF);
swfLoader.load();
var soundTransform:SoundTransform = new SoundTransform(0);
swfLoader.soundTransform = soundTransform;
}
private function loadProgress(event:ProgressEvent):void
{
applicationModel.addToConsoleOutput("SWFPlayer.loadProgress(): " + event.bytesLoaded + " of " + event.bytesTotal + "bytes loaded");
if (MovieClip(swfLoader.content) && event.bytesLoaded < event.bytesTotal)
{
MovieClip(swfLoader.content).gotoAndStop(0);
var soundTransform:SoundTransform = new SoundTransform(0);
swfLoader.soundTransform = soundTransform;
}
}
private function startSWF(event:Event):void
{
swfLoader.removeEventListener(ProgressEvent.PROGRESS, loadProgress);
swfLoader.removeEventListener(Event.COMPLETE, startSWF);
dispatchEvent(new Event("loadComplete", true));
var soundTransform:SoundTransform = new SoundTransform(volume);
swfLoader.soundTransform = soundTransform;
cardMovieClip = MovieClip(swfLoader.content);
cardMovieClip.addEventListener(Event.ENTER_FRAME, endSWFHandler);
cardMovieClip.gotoAndPlay(0);
}