12 Replies Latest reply: Jan 1, 2012 9:42 AM by celebritymusic RSS

    AS3 AIR question

    celebritymusic Community Member

      Hi

       

      I have a desktop AIR app that sends vars to a php page, which then rewrites a new css style file.  After the vars are uploaded, I set off a refresh function in AIR that refreshes an html display pane, so you can see the css style changes on the html page.

       

      I was working great, but since I have changed hosts, I find I have to send the vars twice to see changes. 

       

      I thought maybe the problem was that AIR was displaying the new page before php had a chance to write the new css file, but even after putting a 2 second delay timer on the refresh, the problem still exists.

       

      I have also made the refresh function  URL request append date and time as in:

       

      varSend2 = new URLRequest("http://www.blah.com/"?time=" + new Date().getTime());

       

      Is there a trick to force the html display in AIR to display the new CSS settings first time around?

       

      Thanks guys.

       

      Shaun

        • 1. Re: AS3 AIR question
          kennethkawamoto2 CommunityMVP

          Download the CSS (possibly with a query string appended URL so that you get the new copy) first. When the load is completed download the HTML.

           

          --

          Kenneth Kawamoto

          http://www.materiaprima.co.uk/

          • 2. Re: AS3 AIR question
            celebritymusic Community Member

            Gidday Kenneth

             

            So download the CSS to AIR?  The HTML pane I'm using is just a display that loads an online webpage - I'm not actually using HTML in AIR.  So my programs updates the CSS on the server, and then displays the HTML page.  So I'm not sure how  downloading CSS would fit in with it.  The page gets it's CSS from the server.  Would you be kind enougho elaborate please?

             

            Thanks

            • 3. Re: AS3 AIR question
              kennethkawamoto2 CommunityMVP

              AIR is using cached old CSS, so if you download the new one AIR should use the new CSS - that's my theory.

               

              --

              Kenneth Kawamoto

              http://www.materiaprima.co.uk/

              • 4. Re: AS3 AIR question
                celebritymusic Community Member

                Hi Kenneth

                 

                I've been playing with this for a while now, but cannot figure out how to download the css file to AIR and make AIR use it on the external HTML file loaded into the HTML pane.

                 

                To load the html page, I'm using:

                 

                var htmlPane:HTMLLoader = new HTMLLoader();

                 

                then:

                 

                varSend2 = new URLRequest("my url");

                 

                then, once I've checked it's loaded:

                 

                htmlPane.load(varSend2);

                 

                I can figure out how to apply external css to html that's been loaded into a text field, but not html loaded using HTMLLoader.

                 

                Can you please point me in the right direction so I can research it?

                 

                Thanks again.

                 

                Shaun

                • 5. Re: AS3 AIR question
                  kennethkawamoto2 CommunityMVP

                  First of all try setting HTMLLoader.cacheResponce to false before you load your HTML.

                   

                  If that doesn't work try to load the CSS before you load the HTML. To load a CSS use URLLoader. You may try appending new Date().time to the URL. When the CSS is loaded you can see the result to see if the new version is loaded, but other than that you don't do anything with it. Then finally after the CSS is loaded, load the HTML with HTMLLoader. Because the new CSS has ben downloaded and cached, AIR should use the new CSS (in theory )

                   

                  --

                  Kenneth Kawamoto

                  http://www.materiaprima.co.uk/

                  • 6. Re: AS3 AIR question
                    celebritymusic Community Member

                    Cheers Kenneth.

                     

                    Something screwy is going on.

                     

                    I've set up:

                     

                    var htmlPane:HTMLLoader = new HTMLLoader(); // and later before I load the page...

                     

                    htmlPane.cacheResponse = false;

                    htmlPane.useCache = false;

                     

                    I make a background colour live edit to in my AIR app to black, check the page in Firefox, and the background is black.  Then I check the same page in AIR, and the background is the old colour - green.  I continually make the editor update the page to a black background, and EVENTUALLY it turns black in AIR.  Then other times, it turns black instantly.

                     

                    If an external browser is seeing the new css, why isn't webkit in AIR - especially when I'm using cacheResponse = false?

                     

                    Bizarre.

                    • 7. Re: AS3 AIR question
                      kennethkawamoto2 CommunityMVP

                      The chances are that you're viewing HTML before your new CSS is uploaded fully. Do download the CSS and verify said background colour has been updated - you haven't tried this, have you? 

                       

                      --

                      Kenneth Kawamoto

                      http://www.materiuaprima.co.uk/

                      • 8. Re: AS3 AIR question
                        celebritymusic Community Member

                        LOL - noooooooo.  But I have now, and still having probs.

                         

                        I made a function that loads the css file (with data and time appended).  Once loaded, it goes to the load HTML page function, at the top of which I have trace(event.target.data); so I get an output of the css file data.

                         

                        I try changing the background color, and the new colour is definitely in the css file output, yet webkit in AIR loads the HTML page with the old color.  But it's inconsistent, as sometimes it'll will display the new color just fine.

                         

                        I'm trying a few other things to see if they work, but any other ideas?

                        • 9. Re: AS3 AIR question
                          kennethkawamoto2 CommunityMVP

                          Try StageWebView to see if the CSS gets updated.

                           

                          --

                          Kenneth Kawamoto

                          http://www.materiaprima.co.uk/

                          • 10. Re: AS3 AIR question
                            celebritymusic Community Member

                            StageWebView is just as hit n' miss, although I will replace htmlLoader with it, as it's simpler to get scroll bars up, so thanks for putting me on to it Kenneth.

                             

                            As an experiment, I set up a reload button.  Whenever one of my css edits doesn't show up, I keep pressing the reload button until it does.  Sometimes it  takes over ten reloads before AIR loads the new css (even though the new css is instantly available in IE or FF).  Then other times, the css is there instantly.

                             

                            Is there a way to programatically force a cache flush in AIR?  htmlPane.cacheResponse = false; and htmlPane.useCache = false; weren't making a difference.

                             

                            Thanks for your help on this one Kenneth - if anything, I'm learning new AS3 coding from this!

                            • 11. Re: AS3 AIR question
                              kennethkawamoto2 CommunityMVP

                              I don't think AIR has a built-in function to flush cache. You may be able to delete files in Tempolary Internet Files from AIR, but I've never tried that

                               

                              One thing you can try is in your HTML <link> tag append a time stamp to the CSS URL so that your HTML requests new copy of CSS every time.

                               

                              --

                              Kenneth Kawamoto

                              http://www.materiaprima.co.uk/

                              • 12. Re: AS3 AIR question
                                celebritymusic Community Member

                                Thanks for your help on this one Kenneth - I'll give the time stamp a crack.