17 Replies Latest reply on Jan 10, 2013 5:43 PM by kglad

    Resizing jpegs imported into a swf

    Germaris

      Hi there!

       

      A mere ten per cent of the users of my site upload their photos for use in their profile.

       

      To be sure their data isn't lost, they are stored in both ways: in a dedicated folder and as binary data in a special table of the DB  (a long blob column).

      The whole process of uploading and downloading these images is under control and works nice.

       

      Some users have uploaded more than one photo and, sometimes, they want to change the photo.

      To allow them to choose which photo they want to use, I download them.

       

      The interface the swf offers isn't very large, so I want to resize the downloaded photos at about 250 x 200 pixels each after they download.

      Size significantly larger than usual thumbnails...

      How can I achieve this?

       

      Many thanks in advance for your replies!

        • 1. Re: Resizing jpegs imported into a swf
          kglad Adobe Community Professional & MVP

          to where are the images being downloaded?  to the user's computer file system?  to your swf?  somewhere else?

          • 2. Re: Resizing jpegs imported into a swf
            Germaris Level 1

            Hi, kglad, Happy New Year!

             

            To the swf, of course...

            • 3. Re: Resizing jpegs imported into a swf
              kglad Adobe Community Professional & MVP

              hi (and thank you).

               

              when loading is complete (use preloader code or the moviecliploader class'es onLoadComplete), you can resize the load target.

               

              if you don't understand how to use that info, show the code you're using to load an image.

              1 person found this helpful
              • 4. Re: Resizing jpegs imported into a swf
                Germaris Level 1

                I think I understand what you mean.

                I'll do some tries and give you some feedback...

                 

                Thank you very much!

                • 5. Re: Resizing jpegs imported into a swf
                  kglad Adobe Community Professional & MVP

                  sounds good and, you're welcome.

                  • 6. Re: Resizing jpegs imported into a swf
                    Germaris Level 1

                    Mayday! Mayday!

                     

                    Before thinking about resizing, I should be able to load the picture!

                    Which is not the case...

                     

                    :-(   Grrrrrrr.... Arrrrgh!

                     

                    My PHP Script returns a good jpg file with the appropriate "image/jpeg" header.

                    I tested it in my browser.

                    The picture displays perfectly (it's not a progressive one!)

                     

                    In Flash, I use:

                     

                    historyFct = function () {

                        var ref:String = "35";

                        var myPhotoHistory = new LoadVars();

                        myPhotoHistory.action = "photo_history";

                        myPhotoHistory.ref = ref;

                        myPhotoHistory.onLoad = function(ok) {

                            imageLoader._lockroot = true;

                            pane1.content._lockroot = true;

                            if (ok) {

                                var file = myPhotoHistory.photo1;

                                file.infoLoaded = imageLoader.getBytesLoaded();

                                file.infoTotal = imageLoader.getBytesTotal();

                                percentage = Math.floor(infoLoaded / infoTotal * 100);

                                infoField.text = percentage + "%";

                                if (percentage >= 100) {

                                    pane1.contentPath = this + file;

                                }

                                caption1Fld.text = myPhotoHistory.legend1;

                            }

                            else {

                                countFld.html = true;

                                countFld.htmlText += myPhotoHistory.erreur;

                            }

                        };

                        myPhotoHistory.sendAndLoad("misc.php",myPhotoHistory,"POST");

                    };

                     

                    This a test function in which I set the variable "ref" to an arbitrary value which result I already know.

                     

                    "file" is supposed to load into Loader Component instance "pane1"...

                     

                    I'm quite a bit tired and not able to look at my code with an objective eye...

                    Would you please throw me a lifebelt?

                     

                    Thanks!

                     

                    PS: Of course, I have "import mx.controls.*;" in the first frame of the movie...

                    • 7. Re: Resizing jpegs imported into a swf
                      kglad Adobe Community Professional & MVP

                      i don't see a loadMovie() or loadMovieClip() method anywhere.  you need to fix that to load your image.

                      • 8. Re: Resizing jpegs imported into a swf
                        Germaris Level 1

                        Thanks kglad for responding.

                         

                        Problem is: I have a "mixed" return from the PHP

                        - one variable is a string (the caption for the picture),

                        - the other is "the" picture.

                         

                        May I use LoadMovie in this case?

                        If yes, at which step of the above AS may I use it?

                        • 9. Re: Resizing jpegs imported into a swf
                          kglad Adobe Community Professional & MVP

                          sure.

                           

                          if file is the image name, you would use something like:

                           

                          var target_mc:MovieClip=this.createEmptyMovieClip("target_mc",this.getNextHighestDepth());

                          target_mc.loadMovie(file);

                          1 person found this helpful
                          • 10. Re: Resizing jpegs imported into a swf
                            Germaris Level 1

                            Following is the new script:

                             

                            historyFct = function () {

                                var ref:String = "35";

                                var myPhotoHistory = new LoadVars();

                                myPhotoHistory.action = "photo_history";

                                myPhotoHistory.unlocking = "1";

                                myPhotoHistory.ref = ref;

                                myPhotoHistory.onLoad = function(ok) {

                                    pane1.content._lockroot = true;

                                    if (ok) {

                                        caption1Fld.text = myPhotoHistory.legend1;

                                        var file = myPhotoHistory.photo1;

                                        var target_mc:MovieClip = this.createEmptyMovieClip("target_mc", this.getNextHighestDepth());

                                        target_mc.loadMovie(file);

                                        pane1.content = target_mc.content;

                                        countFld.html = true;

                                        countFld.htmlText += myPhotoHistory.erreur;

                                    }

                                    else {

                                        countFld.html = true;

                                        countFld.htmlText += myPhotoHistory.erreur;

                                    }

                                };

                                myPhotoHistory.sendAndLoad("misc.php",myPhotoHistory,"POST");

                            };

                             

                            and it doesn't work.

                             

                            I think I'd give up for a while...

                             

                            Thank you very much anyway for your time and advices!

                            • 11. Re: Resizing jpegs imported into a swf
                              kglad Adobe Community Professional & MVP

                              use:

                               

                               

                               

                                   var target_mc:MovieClip = this.createEmptyMovieClip("target_mc", this.getNextHighestDepth());

                              historyFct = function () {

                                  var ref:String = "35";

                                  var myPhotoHistory = new LoadVars();

                                  myPhotoHistory.action = "photo_history";

                                  myPhotoHistory.unlocking = "1";

                                  myPhotoHistory.ref = ref;

                                  myPhotoHistory.onLoad = function(ok) {

                                      pane1.content._lockroot = true;

                                      if (ok) {

                                          caption1Fld.text = myPhotoHistory.legend1;

                                          var file = myPhotoHistory.photo1;

                               

                                          target_mc.loadMovie(file);

                                          pane1.content = target_mc.content;

                                          countFld.html = true;

                                          countFld.htmlText += myPhotoHistory.erreur;  // display file in this or, some other textfield to confirm you have a valid file name

                                      }

                                      else {

                                          countFld.html = true;

                                          countFld.htmlText += myPhotoHistory.erreur;

                                      }

                                  };

                                  myPhotoHistory.sendAndLoad("misc.php",myPhotoHistory,"POST");

                              };

                               

                              • 12. Re: Resizing jpegs imported into a swf
                                Germaris Level 1

                                Sorry... doesn't work either...

                                 

                                My PHP Script is efficient.

                                See an example of output at http://www.notre-annuaire.com/loadblob.php

                                So, I don't understand why Flash is unable to load the picture!

                                 

                                About your commented line "

                                // display file in this or, some other textfield to confirm you have a valid file name

                                "

                                I don't understand how can I display "file" which is image data into a text field…???

                                 

                                file name is already there:

                                caption1Fld.text = myPhotoHistory.legend1;

                                as I get it from the DB (and it displays!, it's the only thing I successfully download...).

                                 

                                Sorry to make you wasting time with such a dummy like me…

                                I give up.

                                • 13. Re: Resizing jpegs imported into a swf
                                  kglad Adobe Community Professional & MVP

                                  isn't file a string like "image1.jpg"?

                                  • 14. Re: Resizing jpegs imported into a swf
                                    Germaris Level 1

                                    Hi!

                                     

                                    If you assume that the whole data of the picture is a very very long string, then yes.

                                    So, "file" may be considered as a string...

                                     

                                    But "image1.jpg" is the name of the picture which name is represented in the script by the variable "myPhotoHistory.legend1" and, of course, is also a string...

                                     

                                    For the ease of the communication between us:

                                    file is the data spit by the PHP

                                    legend1 is the name of "file" (displayed as a caption)

                                     

                                    And, as usual, you're right: both are strings!

                                     

                                    :-)

                                    • 15. Re: Resizing jpegs imported into a swf
                                      kglad Adobe Community Professional & MVP

                                      you should be loading legend1 (assuming it's a file name including extension). 

                                       

                                      i don't think there's much you can do with the image data in as2 unless you understand coding (and image file data) thoroughly or you use someone elses image encoder/decoder code.

                                      • 16. Re: Resizing jpegs imported into a swf
                                        Germaris Level 1

                                        Meanwhile, I've found a workaround:

                                         

                                        A Flash function triggers a PHP Script I built which spits out a .jpeg picture from the DB and saves it in a dedicated folder.

                                        At the same time, the PHP Script returns to Flash a variable which populate a text field driven by a listener attached to it.

                                        When the listener notices the "signal", it starts a function which retrieves and downloads to the Flash interface the picture into a Loader component ("signal" is simply the name of the picture file...).

                                         

                                        Maybe it's not very elegant... but it works nice.

                                        Maybe I'll try in the future a solution based on your advices and suggestions.

                                         

                                        Instead of a strong knowledge of coding in Flash, I must have a little creativity...

                                        What do you think?

                                         

                                        Thanks anyway for your time!

                                         

                                        Best regards.

                                        • 17. Re: Resizing jpegs imported into a swf
                                          kglad Adobe Community Professional & MVP

                                          you're welcome.