10 Replies Latest reply on Jun 6, 2010 6:38 PM by webspinner

    Reusing Movie Clip As Target for Loading

    webspinner Level 1

      Hi... been out of the loop for awhile.

       

      I'm in CS3, AS2....

       

      If I use an empty movie clip to load a series of images into,

      how do I get them to load in the center?  The images are all

      different sizes.  I think this is fine, if they loaded with the

      center of both the target clip and the image aligning.

       

      Upper left registration point for the target is not good....

      Too much empty space at lower right...  Do I need to use

      new holder clips for each image?!

       

      Sigh.  There must be a way.

       

      Thanks!

        • 1. Re: Reusing Movie Clip As Target for Loading
          kglad Adobe Community Professional & MVP

          load into an empty movieclip and, when loading is complete, use:


          yourTarget_mc._x = (Stage.width-yourTarget_mc._width)/2;

          yourTarget_mc._y = (Stage.height-yourTarget_mc._height)/2

          1 person found this helpful
          • 2. Re: Reusing Movie Clip As Target for Loading
            webspinner Level 1

            Thanks!  How about if I decide to use AS3?


            • 3. Re: Reusing Movie Clip As Target for Loading
              kglad Adobe Community Professional & MVP

              for as3:

               



              yourTarget_mc.x = (stage.stageWidth-yourTarget_mc.width)/2;

              yourTarget_mc.y = (stage.stageHeight-yourTarget_mc.height)/2

              • 4. Re: Reusing Movie Clip As Target for Loading
                webspinner Level 1

                I can't get the image centered as I want.  There are </= 21 images

                on each page, so to make separate clips and functions would be crazy.

                 

                Here's my code thus far:

                 

                var img1Request:URLRequest = new URLRequest ("blue.jpg");
                var img1Loader:Loader = new Loader();
                load1_mc.addEventListener(MouseEvent.CLICK, ClickF);

                 

                function ClickF(event:MouseEvent):void {
                    img1Loader.load(img1Request)
                    img1Loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadNowF);
                    function loadNowF(event:Event):void {
                        _1.x = (stage.stageWidth-_1.width)/2;
                        _1.y = (stage.stageHeight-_1.height)/2;
                        _1.addChild(img1Loader);
                        trace(stage.stageWidth)
                        trace("x = " + _1.x)
                  }
                }

                 

                 

                It's not really working.  Don't I need to load the image, get the dimensions and use those

                against stageWidth/Height to correctly position them?  They are all different dimensions.

                 

                Thanks!

                • 5. Re: Reusing Movie Clip As Target for Loading
                  kglad Adobe Community Professional & MVP

                  that should be img1Loader:

                   

                  var img1Request:URLRequest = new URLRequest ("blue.jpg");
                  var  img1Loader:Loader = new Loader();
                  load1_mc.addEventListener(MouseEvent.CLICK,  ClickF);

                   

                  function  ClickF(event:MouseEvent):void {
                      img1Loader.load(img1Request)
                       img1Loader.contentLoaderInfo.addEventListener(Event.COMPLETE,  loadNowF);
                      function loadNowF(event:Event):void {
                          img1Loader.x =  (stage.stageWidth-img1Loader.width)/2;
                          img1Loader.y =  (stage.stageHeight-img1Loader.height)/2;
                          _1.addChild(img1Loader);
                    }
                  }

                  1 person found this helpful
                  • 6. Re: Reusing Movie Clip As Target for Loading
                    webspinner Level 1

                    Thanks much.  (Thought I tried it, buuuut)

                     

                    Now, how to set it up so that I can reuse this function?

                    When button #2 gets clicked, how will that image get called?

                    An array, I would imagine.  I have up to 21 buttons calling images.

                     

                    Thanks!


                    Eric

                    • 7. Re: Reusing Movie Clip As Target for Loading
                      kglad Adobe Community Professional & MVP

                      if you're buttons are movieclips you can directly assign an urlS property that points to the string associated with that button's load.  otherwise, you can use an associative array.

                      • 8. Re: Reusing Movie Clip As Target for Loading
                        webspinner Level 1

                        Ok, thanks.  I'll need to think on this one a bit more.


                        • 9. Re: Reusing Movie Clip As Target for Loading
                          kglad Adobe Community Professional & MVP

                          with movieclip buttons:

                           

                           


                          var  img1Loader:Loader = new Loader();

                          load1_mc.urlS = "blue.jpg"

                          load1_mc.addEventListener(MouseEvent.CLICK,  ClickF);

                           

                          function  ClickF(event:MouseEvent):void {
                              img1Loader.load(new URLRequest(MovieClip(event.currentTarget).urlS))
                               img1Loader.contentLoaderInfo.addEventListener(Event.COMPLETE,  loadNowF);
                          }

                           

                          // never nest named functions.  this error is a message i must have copied from your code.

                              function loadNowF(event:Event):void {
                                  img1Loader.x =  (stage.stageWidth-img1Loader.width)/2;
                                  img1Loader.y =  (stage.stageHeight-img1Loader.height)/2;
                                  _1.addChild(img1Loader);
                            }
                          • 10. Re: Reusing Movie Clip As Target for Loading
                            webspinner Level 1

                            Thanks for responding...

                             

                            How would the second button work?

                             

                            Also, I received an error with that code: "1119: Access of possibly undefined property urlS through a reference with static type flash.display:SimpleButton."

                             

                            Thanks!


                            Rick