4 Replies Latest reply on Feb 16, 2013 6:42 PM by Nabren

    Strange Problem - All of my preloaded .swf files play at once


      Hey guys,


        I've been getting a strange problem that I haven't been able to debug.  I recently developed an interactive audio and video treatment program that users click through in which a master swf file (DTM-Start.swf) uses ActionScript upon first being loaded to load the rest of the program in the background.  Here's how the code looks: 


      import flash.display.MovieClip;

      import flash.display.Loader;

      import flash.net.URLRequest;

      import flash.events.Event;


      // create movieclip objects to hold the loaded movies

      var intr1:MovieClip;

      var maladaptIntr1:MovieClip;






      var maladaptIntr1Loader:Loader = new Loader();

      var maladaptIntr1Request:URLRequest = new URLRequest("DTM-Maladapt1.swf");


      maladaptIntr1Loader.contentLoaderInfo.addEventListener(Event.COMPLETE, maladaptIntr1Loaded);


      var intr1Loader:Loader = new Loader(); 

      var intr1Request:URLRequest = new URLRequest("DTM-Intr1.swf");


      intr1Loader.contentLoaderInfo.addEventListener(Event.COMPLETE, intr1Loaded);






      function maladaptIntr1Loaded(event:Event):void


          maladaptIntr1 = event.currentTarget.content as MovieClip;



          maladaptIntr1.y = -1000





      function intr1Loaded(event:Event):void


          intr1 = event.currentTarget.content as MovieClip;



          intr1.y = -1000








      function playIntr1() {

         intr1.y = 0;




      function playMaladapt1() {

          maladaptIntr1.y = 0;








      So that's the idea.  What's strange is that when I load a .swf file compiled with AIR 2.6 (because the user interacts with the movie and a text file is output) it's fine too, but as soon as I add any actionscript, even if it's just a stop() command, to a .swf file compiled with AIR, the DTM-Start.swf loads and then plays all of the movies simultaneously so they're all going off at once.  Essentially, flash seems to be ignoring the maladaptIntr.stop() command in the Loaded function, for instance.  I just don't understand why adding any Actionscript whatsoever to a .swf compiled with AIR would make my DTM-Start do this.  I am very confident this is the issue too, because loading .swf files compiled with the FlashPlayer with action script are fine...AIR .swf files without Actionscript are fine too, it's only AIR .swf files with ANY actionscript that cause this problem....



      Any ideas?


      Much appreciated!





        • 1. Re: Strange Problem - All of my preloaded .swf files play at once
          Nabren Level 3

          Generally timeline code executes after events so if you call stop() in the load event but there is a play() command in the timeline - the play() command would overwrite the stop().


          However, you made it sound like you added a stop() not a play() so I am not quite sure what is going on. But definitely watch out for the order of events - maybe add a trace in your master loader and in your child SWF to see the order of execution and go from there.

          • 2. Re: Strange Problem - All of my preloaded .swf files play at once
            rmacatee Level 1

            So I've added traces in and what seems to be happening is all of the child swfs are getting loaded and playing automatically before any of the Loaded functions get called and add the swf as a child and stop it's execution....in other words, I'm not seeing the trace indicating that Flash has entered the Loaded function until after the .swf files have already been loaded and started to play...Interestingly, on some test runs when Flash just happens to load all of the files rapidly, the Loaded functions do get called and not as many of the .swfs are played automatically so the error is lessened, so this seems to be an issue of variable efficiency onthe part of Flash in terms of getting to all of the loaded functions on time....is there a way for me to pause execution in such a way that flash waits for each specific .swf file to be loaded and its loaded function to be called (where its execution is stopped and its pushed off the screen and added as a child) before moving onto the next .swf to be loaded...and then only proceeding through the main timeline when all of those files have been loaded?  Perhaps a pause function or something like that...?


            Help would be much appreciated!!!

            • 3. Re: Strange Problem - All of my preloaded .swf files play at once
              Amy Blankenship Level 4

              One solution is simply to have a stop() in the constructor of the document Class of each swf you're loading. Another solution is something like:


              package {

                   class MainDocument extends MovieClip {


                   protected var swfs:Array = ['DTM-Maladapt1.swf', 'DTM-Intr1.swf'];

                   protected var positions:Array = [{x:0, y:0}, {x:0, y:0}];

                   protected var movies:Array /*of  MovieClips*/ = [];

                   protected var loadIndex:int;

                   protected var playIndex:int;

                   protected var curremtMovie:MovieClip;


                        public function MainDocument() {





                        protected function loadMovie(loadIndex:int):void {

                             var loader:Loader = new Loader;

                             loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);

                             loader.load(new URLRequest(swfs[loadIndex]));



                        protected function onLoadComplete(e:Event):void {

                             var mc:MovieClip = LoaderInfo(e.currentTarget).content as MovieClip;


                             var position:Object = positions[loadIndex];

                             mc.x = positions.x;

                             mc.y = positions.y;


                             movies[movies.length] = mc;


                             if (loadIndex<swfs.length) {


                             } else {




                        protected function playMovie(playIndex):void{

                             if (currentMovie) {



                             currentMovie = movies[playIndex];





              Note that with this approach you don't need to create a whole new set of logic each time you want to add a new swf to load.

              • 4. Re: Strange Problem - All of my preloaded .swf files play at once
                Nabren Level 3

                As Amy suggested you can definitely add a stop() to each SWF as soon as they load.


                Another solution is in your loader SWF you can use gotoAndStop(1) instead of just stop() to force it back to the first frame if it did play past that before your code was notified.