4 Replies Latest reply on Jan 27, 2010 2:44 AM by Harry Kunz

    Using loadMovie to load swf fails

    Wiizle.nl

      Hello,

       

      I''m currently working on a school project, but I'm having issues with getting the flash loaded with loadMovie.

      I've read on several forums how to use the command, I've also read the help, but I can't figure it out.

      If I use the command, it loads the flash file. But all variables are undefined and the movieclip in which I loaded the swf file also remains empty.

       

      I've tested the situation with a random jpg and this works.

       

      I'm getting kinda desperate, since I've first tried to use scenes without succes..

       

      Thanks!

       

      Greetz!

        • 1. Re: Using loadMovie to load swf fails
          kglad Adobe Community Professional & MVP

          you can't access any of the loaded swf's assets until loading is complete and the loaded swf is initialized.

           

          if you don't understand how that applies to you, post your code that loads your swf and tries to access something in the loaded swf.

          • 2. Re: Using loadMovie to load swf fails
            Wiizle.nl Level 1

            Yes, I know. I've read so. I've also found out that the reason could be that the onLoad event is never called in the loaded swf, which could explain alot.

            I've tried fixing it with the below code:

             

            [as]


            var url:String = "scene05.swf";
                    var movieClip:MovieClip = createEmptyMovieClip("movieClip", 0);
                    
                    var listenerObj:Object = new Object();
                    listenerObj.onLoadComplete = function (target_mc:MovieClip):Void {
                        //It should execute these functions that are located in the onLoad event in the loaded swf.
                        initBackground();
                        initBackgroundWeg();
                        initVehicles();
                        initForeground();
                        initKnoppen();
                    }
                    
                    var movieClipLoader:MovieClipLoader = new MovieClipLoader();
                    movieClipLoader.addListener(listenerObj);
                    movieClipLoader.loadClip(url, movieClip);

            [/as]

             

            Message was edited by: Wiizle.nl

            • 3. Re: Using loadMovie to load swf fails
              kglad Adobe Community Professional & MVP

              onLoadComplete executes before the loaded swf's assets are initialized:  use onLoadInit.

               

              those function definitions in your loaded swf should NOT be in an onLoad method.  if they are defined on the main timeline of the loaded swf, use:

               



              var url:String = "scene05.swf";
                      var movieClip:MovieClip = createEmptyMovieClip("movieClip", 0);
                      
                      var listenerObj:Object = new Object();
                      listenerObj.onLoadInit = function (target_mc:MovieClip):Void {
                          //It should execute these functions that are located in the onLoad event in the loaded swf.
                          target_mc.initBackground();
                          target_mc.initBackgroundWeg();
                          target_mc.initVehicles();
                          target_mc.initForeground();
                          target_mc.initKnoppen();
                      }
                      
                      var movieClipLoader:MovieClipLoader = new MovieClipLoader();
                      movieClipLoader.addListener(listenerObj);
                      movieClipLoader.loadClip(url, movieClip);


              • 4. Re: Using loadMovie to load swf fails
                Harry Kunz Level 4

                Use onLoadInit instead of onLoadComplete.

                 

                import mx.utils.Delegate;

                 

                var url:String = "scene05.swf";
                var movieClip:MovieClip = createEmptyMovieClip("movieClip", 0);
                  
                var listenerObj:Object = new Object();
                listenerObj.onLoadInit = Delegate.create(this, onContentLoad);

                 

                function onContentLoad(target_mc:MovieClip):Void

                {
                   initBackground();
                   initBackgroundWeg();
                   initVehicles();
                   initForeground();
                   initKnoppen();
                }
                        
                var movieClipLoader:MovieClipLoader = new MovieClipLoader();
                movieClipLoader.addListener(listenerObj);
                movieClipLoader.loadClip(url, movieClip);