14 Replies Latest reply on Dec 15, 2009 1:55 PM by BoydMills

    Is this a bug with flex?

    BoydMills Level 1

      Since setStyle takes a string and an object for inputs, one would expect that passing and Image for the Object would  work.  But it doesn't.

       

      One doesn't ALWAYS have a filename to work with.  Is setStyle supposed to work with parameters: (string,object) ("backgroundImage", Image)?

       

      If so, what else needs to be done?

       

       

       

       

       

      ===========

       

       

      private function GetConfigurationResult( event:WsVCIGetConfigurationDataResultEvent):void

      var simage:String = event.result.Image;

      var decoded:ByteArray;

      var

      decoder.decode( simage );

      decoded = decoder.toByteArray( );

      bgImage.data = decoded;

       

      decoder:Base64Decoder = new Base64Decoder();

      "backgroundImage", bgImage );

      setStyle(

      }

       

      ============

      But this generates the following error:

      ==========

      Error: Unable to load 'Image52'.
      at mx.skins::RectangularBorder/updateDisplayList()[C:\autobuild\3.2.0\frameworks\p rojects\framework\src\mx\skins\RectangularBorder.as:237]
      at mx.skins.halo::HaloBorder/updateDisplayList()[C:\autobuild\3.2.0\frameworks\pro jects\framework\src\mx\skins\halo\HaloBorder.as:222]
      at mx.skins::ProgrammaticSkin/validateDisplayList()[C:\autobuild\3.2.0\frameworks\ projects\framework\src\mx\skins\ProgrammaticSkin.as:421]
      at mx.managers::LayoutManager/validateDisplayList()[C:\autobuild\3.2.0\frameworks\ projects\framework\src\mx\managers\LayoutManager.as:622]
      at mx.managers::LayoutManager/doPhasedInstantiation()[C:\autobuild\3.2.0\framework s\projects\framework\src\mx\managers\LayoutManager.as:677]
      at Function/http://adobe.com/AS3/2006/builtin::apply()
      at mx.core::UIComponent/callLaterDispatcher2()[C:\autobuild\3.2.0\frameworks\proje cts\framework\src\mx\core\UIComponent.as:8628]
      at mx.core::UIComponent/callLaterDispatcher()[C:\autobuild\3.2.0\frameworks\projec ts\framework\src\mx\core\UIComponent.as:8568]

       

      ==============

       

       

      But passing a filename to setStyle works!!!!

       

      But I need the image to come from a database by way of web server!!!!!!

       

      Help!

      {// retrieve the 64base encoded image from the web service by ResultEvent

      var

       

      bgImage:Image =new Image();

        • 1. Re: Is this a bug with flex?
          Flex harUI Adobe Employee

          setStyle can take just about anything for the second parameter.  What matters is what kind of thing the consumer of that style expects.  Most of the skin styles in Flex take classes, not instances, which means that Image won't work if it is a instance of an mx:Image and not the class itself (which wouldn't do you any good because you'd have no way to specify the source for the mx:Image).

           

          Alex Harui

          Flex SDK Developer

          Adobe Systems Inc.

          Blog: http://blogs.adobe.com/aharui

          • 2. Re: Is this a bug with flex?
            BoydMills Level 1

            Answers the question about {setStyle("backgroundImage", Image )} but doesn't solve my problem.

             

            a) I need to extract the background image from a database, capture it in a bytearray buffer.

            b) mx: command { backgroundImage="assets/images/initialdisplay.jpg" } requires the the image be loaded before the database can be accessed, and requires a prederimined file.  Both words "predetermined" and "file" are an issue.

            c) setStyle("backgroundImage", Image ) doesn't work either.

             

             

            I can see the proposed solution now:

            a) get the image from the database

            b) place it into a fileref structure

            c) upload the file to the server

            d) then use setStyle("backgroundImage", filename )

             

            That sounds somewhat less than elegant and quite a burden on the network!

             

            Any suggestions?

            • 3. Re: Is this a bug with flex?
              paul.williams Level 4

              As far as I can tell, the background image is loaded inside the RectangularBorder class. It will support an image as a class (skin or embedded image), or as a string (url or file-path). It isn't coded to support an image passed in as data.

               

              You could extend HaloBorder to add an Image control as a background and pass your image data into it. You could add an Image as the first child of your component (width, height = 100%) and assign the image data to it. Or you could set backgroundAlpha to zero and position an Image behind your component.

               

              Alternatively from your "GetConfiguration" server-call you could return a url to a service that returns the image from the database.

              • 4. Re: Is this a bug with flex?
                BoydMills Level 1

                I like the idea of:

                 

                "Alternatively from your "GetConfiguration" server-call you could return a url to a service that returns the image from the database."

                 

                I presume the url of the web service would then be passed as:

                   setStyle( "backgroundImage", url ); // where url is a string

                 

                Could you point me to an example, for instance does the service return a bytearray?

                 

                 

                 

                /Boyd

                • 5. Re: Is this a bug with flex?
                  paul.williams Level 4

                  I don't know what server-side technology you are using, but I this is quite a common question on java forums:

                   

                  http://www.jguru.com/faq/view.jsp?EID=159

                   

                  When you download a jpeg at a particular url the server just gives you back a bunch of bytes with a content type of "image/jpg". You just need your server to load those bytes from the database rather than from a disk.

                   

                  So from the client's point-of-view it is still just loading an image from a url.

                  • 6. Re: Is this a bug with flex?
                    BoydMills Level 1

                    I am using web services created with MS Visual Studio 2005 and hosted by asp.net on iis7 on MS Server 2008.

                     

                    Should the response be binary, base64encoded, .....?

                     

                    /Boyd

                    • 7. Re: Is this a bug with flex?
                      BoydMills Level 1

                      newbie type question.

                       

                      In my .mxml code file I have the line:

                       

                       

                       

                       

                      <mx:Image id="myBackGround" width="100" height="100" alpha="0" />

                       

                       

                      Then in my .as code file, how do I reference this image?

                       

                      Or is the <mx:Image line improperly defined?  should it somehow refer to the Image variable in the .as file?

                      • 8. Re: Is this a bug with flex?
                        BoydMills Level 1

                        The code now reads:

                         

                         

                        private function GetConfigurationResult( event:WsVCIGetConfigurationDataResultEvent):void

                        {

                         

                         

                        var myUrl:URLRequest;

                        var servername:String = this.parentApplication.VCIFormsPage.text;

                        var lFileName:String = event.result.FileName+event.result.FileExtension;

                        myUrl = new URLRequest();

                        myUrl.url = servername + "VCIWebFileRetrieve.aspx?filename=" + lFileName ;

                         

                         

                        setStyle("backgroundImage", myUrl );

                         

                        }

                         

                        and I still get:

                        Error: Unable to load '[object URLRequest]'.
                        at mx.skins::RectangularBorder/updateDisplayList()[C:\autobuild\3.2.0\frameworks\projects\fr amework\src\mx\skins\RectangularBorder.as:237]
                        at mx.skins.halo::HaloBorder/updateDisplayList()[C:\autobuild\3.2.0\frameworks\projects\fram ework\src\mx\skins\halo\HaloBorder.as:222]

                        ...

                         

                        The URL is a web form to compose and return a "file"

                         

                         

                        This still isn't working!

                         

                        Did I do something wrong, like maybe I should use something other than "URLRequest?"

                        • 9. Re: Is this a bug with flex?
                          msakrejda Level 4

                          The backgroundImage needs to be a String representation of a url, not a URLRequest. Try the following:

                           

                           

                          private function GetConfigurationResult( event:WsVCIGetConfigurationDataResultEvent):void

                          {

                          var servername:String = this.parentApplication.VCIFormsPage.text;

                          var lFileName:String = event.result.FileName+event.result.FileExtension;

                           

                          setStyle("backgroundImage", servername + "VCIWebFileRetrieve.aspx?filename=" + lFileName );

                          }

                          • 10. Re: Is this a bug with flex?
                            PhilipKeiter Level 2

                            If you run into a situation where you are fixed on loading bytes from the DataBase and don't want to convert it to a file server side, a simple work around would be to use an absolute layout container and put an image in it at the lowest level, rather than set the backgroundImage of the container.

                            • 11. Re: Is this a bug with flex?
                              BoydMills Level 1

                              That seems to have got me past the next hurdle

                               

                              but now I get the error:

                              Error #2044: Unhandled SecurityErrorEvent:. text=Error #2190: The attempted load of http://xyz.com/LOADER/VCIWebFileRetrieve.aspx?filename= anibell failed as it had a Content-Disposition of attachment set.

                               

                               

                              My web form page presents the data:

                              -----

                              Response.Clear();

                              Response.AddHeader(

                              "Content-Disposition", "attachment; filename=" +filename );//+ext?

                              Response.AddHeader(

                              "Content-Length", len.ToString());

                              Response.ContentType =

                              "application/octet-stream";

                               

                              if (len != 0)

                              {

                              Response.BinaryWrite(data);

                              Response.StatusCode = 200;

                              }

                               

                              else

                              {

                              Response.StatusCode = 500;

                              }

                              Response.End();

                              --------------

                               

                               

                              I presume the setStyle("backgroundImage", url:string);  wants something different in the response.addheader or .ContentType sections.

                               

                               

                              Please advise!

                               

                              Regards,

                              Boyd

                               

                               

                              • 12. Re: Is this a bug with flex?
                                PhilipKeiter Level 2

                                Message was edited by: Philip Keiter

                                • 13. Re: Is this a bug with flex?
                                  msakrejda Level 4

                                  Why setting the Content-Disposition to 'attachment'? Ideally, the URL should point at something that's indistinguishable from a plain file. I.e., if you go that URL in your browser, you should just see the image, as if it were a standard path in your web app that contained a static image.

                                  • 14. Re: Is this a bug with flex?
                                    BoydMills Level 1

                                    I removed all the stuff:

                                    ------------

                                    }

                                    Response.Clear();

                                     

                                     

                                    //Response.AddHeader("Content-Disposition", "attachment; filename=" +filename );//+ext?

                                     

                                     

                                    //Response.AddHeader("Content-Length", len.ToString());

                                     

                                     

                                    //Response.ContentType = "application/octet-stream";

                                     

                                     

                                    if (len != 0)

                                    {

                                    Response.BinaryWrite(data);

                                    Response.StatusCode = 200;

                                    }

                                     

                                    else

                                    {

                                    Response.StatusCode = 500;

                                    }

                                    Response.End();

                                    -----------

                                     

                                    and now it works!!!!!

                                     

                                     

                                     

                                    But rather than depend on the defaults, is there anything that SHOULD be entered in the "addheader" clause?