8 Replies Latest reply on Aug 29, 2008 5:55 PM by ZodiacHSX

    Support for data: urls?

    ZodiacHSX Level 1
      Very short question: Has any version of Flash support for data:urls for images?
        • 1. Re: Support for data: urls?
          Level 7
          >>data:urls

          eh? Please explain yourself better.

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


          • 2. Re: Support for data: urls?
            ZodiacHSX Level 1
            Sorry, data urls are a pseudo protocol handler, similar to mailto:, meaning that when you "get" such an url, no actual request to the server happens, instead the request is treated internally be the client. For example, a mailto: link might lauch the mail client.

            data urls similary, don't send a request to the server. Instead, the url already contains all the data and when requesting download of such an url, the data contained in the url is decoded and returned as the response.

            A very simple example would be
            data:text/plain,Hello World
            which when requested returns a text/plain MIME document containing the string "Hello World"

            similarly, binary data can be stored using data urls and a base64 encoding. For example, this will spit out a single pixel PNG:
            data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGD4DwAB BAEAfbLI3wAAAABJRU5ErkJggg==

            These are supported in all major browsers (beside Internet Explorer, of course) and can be used for a variety of purposes, ranging from accelerating page loading by saving HTTP requests to initiating downloads by replacing the MIME. For example, this url will initate a download of the single pixel PNG
            data:application/octetstream;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQV QImWNgYGD4DwABBAEAfbLI3wAAAABJRU5ErkJggg==

            And that's precisely what I want to happen inside Flash if possible, as (thanks to Internet Explorer) I can't be sure in the browser.
            • 3. Re: Support for data: urls?
              Level 7
              Hmmm, AFAIK Flash has no direct support for such a thing. I'd think you
              could write some code to simulate at least some of it though. Can you give
              some indication of exactly what you're trying to do? It might be that you
              simply need to approach it differently.

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


              • 4. Re: Support for data: urls?
                ZodiacHSX Level 1
                For one I want to offer a dynamically created image for download to the user. Then I need to send image data between multiple instances of Flash as well as between Flash and HTML.
                • 5. Re: Support for data: urls?
                  Level 7
                  >>For one I want to offer a dynamically created image for download to the
                  >>user. Then I need to send image data between multiple instances of Flash
                  >>as well as between Flash and HTML.


                  All doable... and there are many examples of allowing users to save images
                  from Flash.

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


                  • 6. Re: Support for data: urls?
                    ZodiacHSX Level 1
                    Could you be a little more specific... I did some searching, but I can't find anything, probably because I don't know the Flash lingo for these things.

                    I know I can get an image into a ByteArray, but how do I offer them? download needs a file to work and the externalInterface is too primitive to send anything but text, which would mean creating a surface, rendering it into a byte array, encoding it with an AS port of Zlib to PNG, doing a base64 encode and shoving it out as string... that's simply not possible, the user would have to wait several seconds for a 50k file.
                    • 7. Re: Support for data: urls?
                      Level 7
                      Just do some searching on saving jpeg from Flash. If you're using AS3,
                      there's a JPEG encoder built in, and ByteArray has a compress() method which
                      uses zlib.

                      Here's a start: http://henryjones.us/articles/using-the-as3-jpeg-encoder


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


                      • 8. Re: Support for data: urls?
                        ZodiacHSX Level 1
                        I'm using AS2 and as the whole point is having a fallback for outdated browsers I don't really want to touch AS3. Is there a way to simply communicate image data (no matter the format) between seperate Flash Plugin instances on the same page?