13 Replies Latest reply on Oct 20, 2008 5:50 AM by Newsgroup_User

    Resizing an image after loading

    Venian Level 2
      Hi.
      I'm loading an image into a movieclip by loadMovie.
      After i load it i want to resize it so it fits in a specific place. The problem is that the resize doesn't work on it.
      The code:

      load_mc.loadMovie("image.jpg");
      load_mc._width = 160;
      load_mc._height = 90;

      I even tried to use an onEnterFrame thinking that it wasn't fully loaded by the time the resize started. Still doesn't work.
      The picture is displayed but at it's full size. No resize happens.

      Can anyone help me resize it after it's loaded?

      Thank you.

        • 1. Re: Resizing an image after loading
          clbeech Level 3
          yes - one can't implement changes to the loaded clip/image until after it has become instantiated on the timeline. so in this case it would be better to use the MovieClipLoader class to load the image, which provides a handler for an event called onLoadInit() - here's how you do it:

          PS. setting the _width and _height will only increase the 'size' of the clip bounds, not increase the size of the image
          • 2. Re: Resizing an image after loading
            Venian Level 2
            Thanks man. I love you guys. I always been given help everytime i used this forum.

            what's /clip._width *100; for?
            To keep the proportion or what?

            Thanks again.
            • 3. Re: Resizing an image after loading
              Level 7
              >>PS. setting the _width and _height will only increase the 'size' of the
              >>clip
              bounds, not increase the size of the image

              Eh??? Setting the _width and _height of the clip will affect the image... I
              never use the scale(s) and resize images all the time.

              --
              Dave -
              www.offroadfire.com
              Head Developer
              http://www.blurredistinction.com
              Adobe Community Expert
              http://www.adobe.com/communities/experts/


              • 4. Re: Resizing an image after loading
                Venian Level 2
                Ok. Thanks.

                I've used the code you gave me and onLoadInit doesn't work.

                It gives errors ar compile time.

                lstn.onLoadInit(clip) {
                clip._xscale = 160 / clip._width * 100;
                clip._yscale = 90 / clip._height * 100;
                }
                mcl.loadClip('image.jpg', load_mc);

                clip shouldn't be load_mc?
                • 5. Re: Resizing an image after loading
                  Rothrock Level 5
                  I agree with Dave I almost never use _xscale/_yscale. You can just set the _width and _height.

                  Venian -- generally if something gives and error it is helpful to know what that error is! :)

                  The code should give any error at compile time. If somehow _width was zero then you would be dividing by zero and it could cause a problem at runtime....

                  • 6. Re: Resizing an image after loading
                    Venian Level 2
                    Thank guys. It work. There was a sintax problem. but now it work. Thanks a lot. You saved me from lots of trouble.
                    • 7. Re: Resizing an image after loading
                      clbeech Level 3
                      @Dave & RR - LOL! sure does - don't know what i was thinking, brain fart - PHA HA!

                      (i think i must have resorted to that a long while back before understanding instantiation and the mcl class and been 'thinking' that ever since LOL!)

                      thanks for correcting me :)
                      • 8. Re: Resizing an image after loading
                        Level 7
                        >>i think i must have resorted to that a long while back before
                        >>understanding
                        instantiation and the mcl class and been 'thinking' that ever since LOL!

                        Hehe... I understand how that goes for sure.

                        --
                        Dave -
                        www.offroadfire.com
                        Head Developer
                        http://www.blurredistinction.com
                        Adobe Community Expert
                        http://www.adobe.com/communities/experts/


                        • 9. Re: Resizing an image after loading
                          Level 7
                          You have lstn.onLoadInit but mcl.loadClip... those work on the same instance
                          of MovieClipLoader. So if you do:

                          var mcl = new MovieClipLoader();

                          You'd do:

                          mcl.onLoadInit = function...

                          Just look in Help for the MovieClipLoader class's onLoadInit method. It has
                          everything you need.

                          --
                          Dave -
                          www.offroadfire.com
                          Head Developer
                          http://www.blurredistinction.com
                          Adobe Community Expert
                          http://www.adobe.com/communities/experts/


                          • 10. Re: Resizing an image after loading
                            clbeech Level 3
                            oh yeah - totally mistyped the handler - but Dave I've been using MCL for a quite a while now and aren't you 'suppose' to add the listener Obj? it of course should have been declared as:

                            lstn.onLoadInit = function(clip) { ... }

                            but I didn't realize that you can use the mcl as the listener? seems like every 10 posts or so is someone needing a mcl and I've given advice on the mcl many times - so i find that really interesting that you can run it without the listener obj!?!?!? crazy LOL! in the constructor def it sure does look like you can (i just reviewed) and tested, and TA DA! sure enough you can - wow that's a time/confusion saver lol - thanks Dave

                            odd though that in the actual method definitions code examples they do use the additional listener - i suppose it's more 'proper' OOP or something? any thoughts? (i suppose teach the 'right' way first then show the shortcuts lol)
                            • 11. Re: Resizing an image after loading
                              Level 7
                              >>odd though that in the actual method definitions code examples they do use
                              >>the additional listener...

                              Geez... I guess we both had brain farts in this thread! You are, of course,
                              right - the examples do use a listener and now that I think about it more I
                              suppose I do to. I use my custom loader class so much I haven't coded a new
                              one for a little while now, and just told him the wrong way. I hate doing
                              that... But it works eh? Hmmm... I guess considering it's made to have a
                              listener attached that one should be used.

                              Sorry for the confusion.

                              --
                              Dave -
                              www.offroadfire.com
                              Head Developer
                              http://www.blurredistinction.com
                              Adobe Community Expert
                              http://www.adobe.com/communities/experts/


                              • 12. Re: Resizing an image after loading
                                clbeech Level 3
                                LOL! hey np Dave - I always bow to your superior wisdom :D I think it was cool that it actually works, i suppose it's an object like anything, so it could potentially listen to itself talking... PHA HA! surprising that it would 'hear' it though without even 'adding' ITSELF as a listener obj, must be the default or something.

                                I've only been 'back' into coding for a few years now, and find it funny how one starts thinking in terms of classes and methods that you've defined and use regularly isn't it, guess that's why there are so many different languages and methodologies, often to achieve the same result :)
                                • 13. Re: Resizing an image after loading
                                  Level 7
                                  Thanks, that's really too nice. I was doing a little digging on this - why
                                  adding the function to the class works. Check it out:

                                  var mcl = new MovieClipLoader();
                                  trace(mcl._listeners.length);

                                  you will get 1 - not 0. The class itself must be registered as a listener by
                                  default?

                                  I'm not entirely sure. I dug a little through the Flash classes, and while I
                                  didn't find exactly what I was after I did find this within the
                                  EventDispatcher class' dispatchEvent method:

                                  if (eventObj.target == undefined)
                                  eventObj.target = this;

                                  So, if there's no target the method would get called on the class, as we
                                  saw.



                                  --
                                  Dave -
                                  www.offroadfire.com
                                  Head Developer
                                  http://www.blurredistinction.com
                                  Adobe Community Expert
                                  http://www.adobe.com/communities/experts/