17 Replies Latest reply on Sep 18, 2009 11:10 AM by kglad

    Loading a .swf but doesn't keep size of original .swf...?

    videostart

      Hi!

       

      I'm attemping to load a swf into my movie. 
      I have this code:

       

      but.onPress = function() {
      _root.floors.createEmptyMovieClip("container",2);
      loadMovie("zoom.swf", "container");
      container._x = -460;
      container._y = -200;
      };

      stop();

       

      It loads in fine, but it is not staying the size of the stage of the .swf it was in before.

       

      I tried setting the width and height of the container clip by:

       

      container._width = 500;
      container._height = 100;

       

      but once i added that it didn't load in?

       

      Any thoughts...?

        • 1. Re: Loading a .swf but doesn't keep size of original .swf...?
          kglad Adobe Community Professional & MVP

          you can assign container's _width and _height AFTER loading is complete.

          • 2. Re: Loading a .swf but doesn't keep size of original .swf...?
            videostart Level 1

            Is there an if statement I can create to check if it's loaded?

            • 3. Re: Loading a .swf but doesn't keep size of original .swf...?
              videostart Level 1

              I found this to use as an example.....I added a loadMovieNum("zoom.swf") at the end, but I think I'm missing something...?

               

              function preload(movie2load:String, container:MovieClip):Void {

               

                   // set the mc variable to our current movie & create a placeholder

                   var mc = container.createEmptyMovieClip("loader_mc", container.getNextHighestDepth());

                   //record our containers width and height

                   var w:Number = container._width;

                   var h:Number = container._height;

                   mc._x = 0;// set its _x position

                   mc._y = 0;// set its _y position

                   mc._alpha = 0;

                   // load the first swf into our mc

                   mc.loadMovie(movie2load);

                   // preload loop

                   this.onEnterFrame = function() {

               

                        var Percent:Number = Math.round((mc.getBytesLoaded()/mc.getBytesTotal())*100);

                        // if Percent is a number

                        if (!isNaN(Percent)) {

                             trace("loading "movie2load" "Percent"%");

                        }

                        // if Percent, of the current movie, has reached 100                                                                          

                        if (Percent == 100) {

               

                             trace("done loading");

                             //resize our loaded mc

                             mc._width = w;

                             mc._height = h;

                             //show our loaded mc

                             mc._alpha = 100;

                             //delete loop

                             delete this.onEnterFrame;

                        }

                   };

              }

               

              preload("zoom.swf",container);

               

               

              stop();

              • 4. Re: Loading a .swf but doesn't keep size of original .swf...?
                kglad Adobe Community Professional & MVP

                w and h are probably both 0.  use the trace() function to check.

                • 5. Re: Loading a .swf but doesn't keep size of original .swf...?
                  videostart Level 1

                  I changed some things in the code, I added zoom.swf into this line:  mc.loadMovie(zoom.swf);

                  I also set the width and height to 100, 200, but neither of the traces in the if statements seem to be working, so

                  Why is this.onEnterFrame function not working? 

                   

                  I have this code on the button, is that a problem?

                   

                  on (release) {

                       function preload(movie2load:String, container:MovieClip):Void {

                   

                            // set the mc variable to our current movie & create a placeholder

                            var mc = container.createEmptyMovieClip("loader_mc", container.getNextHighestDepth());

                            //record our containers width and height

                            var w:Number = container._width;

                            var h:Number = container._height;

                            mc._x = 0;// set its _x position

                            mc._y = 0;// set its _y position

                            mc._alpha = 0;

                            // load the first swf into our mc

                            mc.loadMovie(zoom.swf);

                            // preload loop

                            this.onEnterFrame = function() {

                   

                                 var Percent:Number = Math.round((mc.getBytesLoaded()/mc.getBytesTotal())*100);

                                 // if Percent is a number

                                 if (!isNaN(Percent)) {

                                      trace("loading "zoom.swf" "Percent"%");

                                 }

                                 // if Percent, of the current movie, has reached 100                                                                               

                  if (Percent == 100) {

                   

                                      trace("done loading");

                                      //resize our loaded mc

                                      mc._width = 100;

                                      mc._height = 200;

                   

                                      //show our loaded mc

                                      mc._alpha = 100;

                                      //delete loop

                                      delete this.onEnterFrame;

                                 }

                            };

                       }

                       preload("zoom.swf",container);

                   

                       //trace("end")

                  }

                  • 6. Re: Loading a .swf but doesn't keep size of original .swf...?
                    kglad Adobe Community Professional & MVP

                    yes, you have problems.

                     

                    1.  never nest named functions.  there's no benefit and one significant drawback.

                     

                    2.  you shouldn't attach any code to objects.  there's no benefit and many drawbacks.

                     

                    3.  copy and paste your code using ctrl-c and ctrl-v, resp.

                    • 7. Re: Loading a .swf but doesn't keep size of original .swf...?
                      videostart Level 1

                      So all of the functions should be on the main timeline, separated?

                      The code I posted was from a help file I found online.

                      • 8. Re: Loading a .swf but doesn't keep size of original .swf...?
                        kglad Adobe Community Professional & MVP

                        there's plenty of poor coding online just like there's plenty of misinformation online.

                         

                        and yes, named functions should be separated:

                         

                        this.onRelease=function(){

                        function nameF(){

                        //

                        }

                        nameF();

                        etc

                        }

                         

                        should be

                         

                        this.onRelease=function(){

                        nameF();

                        //etc

                        }

                        function nameF(){

                        }

                         

                        you can nest anonymous functions.  that's can bereasonable:

                         

                        this.onRelease=function(){

                        this.onEnterFrame=function(){

                        this._x+=3;

                        if(this._x>=333){

                        delete this.onEnterFrame;

                        }

                        }

                        1 person found this helpful
                        • 9. Re: Loading a .swf but doesn't keep size of original .swf...?
                          videostart Level 1

                          I agree with that!  Do you know of a good tutorial I can do for preloading the mc, once I can go through that I'll post back with a more developed question.....I appreciate the help!

                          • 10. Re: Loading a .swf but doesn't keep size of original .swf...?
                            kglad Adobe Community Professional & MVP

                            rather than learn how to preload you should learn how to use the moviecliploader class.  the coding is cleaner and harder to mess-up.

                             

                            var mcl:MovieClipLoader=new MovieClipLoader();

                            var lo:Object=new Object();

                            lo.onLoadInit=function(target:MovieClip){

                            //loading is complete and you're ready to resize:

                            target._width=whatever;

                            target._height=...;

                            }

                            mcl.addListener(lo);

                            mcl.loadClip("yourswf.swf",yourEmptyTargetMC);

                             

                            // if you want to display the load progress, add:

                             

                            lo.onLoadProgress=function(target:MovieClip,bl:Number,bt:Number){

                            //where bl=bytes loaded and bt=bytes total

                            }

                            1 person found this helpful
                            • 11. Re: Loading a .swf but doesn't keep size of original .swf...?
                              videostart Level 1

                              Can I use this in AS2 or is it just for AS3?

                               

                              The project that I'm working in is set up for AS2.

                              • 13. Re: Loading a .swf but doesn't keep size of original .swf...?
                                videostart Level 1

                                Ok, whatever is less easy to mess-up!

                                 

                                I replaced my items in your code below:

                                 

                                var mcl:MovieClipLoader = new MovieClipLoader();

                                var lo:Object = new Object();

                                lo.onLoadInit = function(target:MovieClip) {

                                     //loading is complete and you're ready to resize:

                                     target._width = 200;

                                     target._height = 200;

                                };

                                mcl.addListener(lo);

                                 

                                 

                                mcl.loadClip("zoom.swf",testing_mc);

                                 

                                 

                                zoom.swf is the file that needs loaded (btw, zoom.swf loads in a .swf file, not sure if that's part of the problem)

                                and target_mc is the mc that zoom.swf should resize in.

                                 

                                when I trace mc1, it shows up as undefined?

                                • 14. Re: Loading a .swf but doesn't keep size of original .swf...?
                                  kglad Adobe Community Professional & MVP

                                  what's mc1 and what's target_mc?

                                  • 15. Re: Loading a .swf but doesn't keep size of original .swf...?
                                    videostart Level 1

                                    Mc1 seems to be the variable?? And target_mc is what the .swf would get loaded into??

                                    Am I close?

                                    • 16. Re: Loading a .swf but doesn't keep size of original .swf...?
                                      kglad Adobe Community Professional & MVP

                                      you're not being careful enough for programming in actionscript.   flash is not clever enough to determine that you mean mc1 when you type Mc1 or that you mean mcl when you type mc1.   and, in fact, i'm not sure what you mean anymore either.

                                      • 17. Re: Loading a .swf but doesn't keep size of original .swf...?
                                        videostart Level 1

                                        I'm trying to work with the code that you posted.  mcl is the var? correct?

                                         

                                        var mcl:MovieClipLoader = new MovieClipLoader();

                                        var lo:Object = new Object();

                                        lo.onLoadInit = function(target:MovieClip) {

                                             //loading is complete and you're ready to resize:

                                             target._width = 200;

                                             target._height = 200;

                                        };

                                        mcl.addListener(lo);

                                         

                                         

                                        mcl.loadClip("zoom.swf",testing_mc);