Skip navigation
Currently Being Moderated

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

Feb 14, 2013 2:45 PM

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;




// 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!





  • Currently Being Moderated
    Feb 14, 2013 3:06 PM   in reply to rmacatee

    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.

    Mark as:
  • Currently Being Moderated
    Feb 16, 2013 7:52 AM   in reply to rmacatee

    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.

    Mark as:
  • Currently Being Moderated
    Feb 16, 2013 6:42 PM   in reply to rmacatee

    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.

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points