7 Replies Latest reply on Jun 10, 2010 6:41 AM by uzairseedat

    Image update problem

    uzairseedat

      I have an image control in my application which loads an image from the assets folder. Then I use FileReference object to browse and upload the image to a service. The service replaces the image with same name and extension in the assets folder. Finally I try to load the image again but it keeps on showing the previous one. However, when I run the application again, the new image is loaded. How do I get the latest image to show up as soon as the upload is finished?

        • 1. Re: Image update problem
          David_F57 Level 5

          hi,

           

          this is what the upload and return should look like

           

          private var fr:FileReference = new FileReference();

           

           

          private function uploadimage():void {

          fr.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,onUploadCompleteData);

          fr.upload(myURLRequest);

          }

           

          private function onUploadCompleteData(event:DataEvent):void

          {

          fr.removeEventListener(DataEvent.UPLOAD_COMPLETE_DATA,onUploadCompleteData);

          downloadimage();

          }

           

          David

          • 2. Re: Image update problem
            uzairseedat Level 1

            This is code I currently have in my Cairngorm Command that is reponsible for the upload operation:

             

            ////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////

            protected function uploadLogo():void

                    {

                        try

                         {

                            var urlRequest:URLRequest = new URLRequest("http://localhost:2333/FileUploader/upload.ashx");       

             

                            this.fileReference.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, updateLogo);

             

                             this.fileReference.upload(urlRequest);

                         }

                         catch(error:Error)

                         {

             

                         }

                    }

             

                    protected function updateLogo(e:DataEvent):void

                    {

                        this.fileReference.removeEventListener(DataEvent.UPLOAD_COMPLETE_DATA, updateLogo);

             

                        var app:Application = this.parentApplication as Application;

             

                        var siteLogo:Image = this.parentApplication["imgLogo"] as Image;

             

                        siteLogo.load("assets/images/logo.jpg");

                    }

            ////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////

            • 3. Re: Image update problem
              David_F57 Level 5

              hi,

               

              do you have a load complete event for the image, you need to refresh the image once it has loaded the new data.

               

              David.

              • 4. Re: Image update problem
                uzairseedat Level 1

                I cant find Load_Complete event on image. Could you plz specify the exact event I should work upon? Thanks in advance.

                • 5. Re: Image update problem
                  uzairseedat Level 1

                  Even I've tried using a Java servlet for this and the result is same

                   

                  ////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////

                   

                  protected function uploadLogo():void
                          {
                              try
                               {               
                                  var urlRequest:URLRequest = new URLRequest("/FrontApp/FileUpload");
                                 
                                  this.fileReference.addEventListener(Event.COMPLETE, updateLogo);
                                  
                                   this.fileReference.upload(urlRequest);   
                               }
                               catch(error:Error)
                               {
                                   Alert.show("Unable to upload logo to server","Error", Alert.OK, null, null, model.errorIcon);
                               }
                          }
                         
                          protected function updateLogo(e:Event):void
                          {
                              //fetch site logo
                              this.imageLoader= new Loader();
                             
                              var imageRequest:URLRequest = new URLRequest("assets/images/siteLogo.PNG");
                         
                              this.imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadImage);
                              this.imageLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loadFailed);
                             
                              var context:LoaderContext = new LoaderContext();
                              context.applicationDomain = ApplicationDomain.currentDomain;
                             
                              this.imageLoader.load(imageRequest, context);
                          }

                   

                        protected function loadImage(e:Event):void
                          {
                             
                              if(this.imageLoader.content)
                              {
                                  model.siteLogo = this.imageLoader.content as Bitmap;
                              }
                          }

                   

                  ////////////////////////////////////////////////////////////////////////////////////////// //////////////

                  • 6. Re: Image update problem
                    UbuntuPenguin Level 4

                    He's probably referring to the EVENT.COMPLETE found here

                    http://livedocs.adobe.com/flex/3/langref/mx/controls/Image.html#eventSummary

                    • 7. Re: Image update problem
                      uzairseedat Level 1

                      Hmm... but if you observe my latest reply above, I've already used it. The thing works perfect except that I need to clear my browser cache once when the application is running. After that, the image updates itself perfectly.