A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: [AS3] how do i prevent caching of images?

  1. #1
    Senior Member bluemagica's Avatar
    Join Date
    Jun 2008
    Posts
    766

    [AS3] how do i prevent caching of images?

    I have to load png images into flash, such that, whenever they change on server, the change should be reflected on client! But the swf loads the same image over and over during the same session! I am guessing this is because the browser returns the cached image instead of the original! So any idea how to fix this?

  2. #2
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    not sure if it still works in as3 but you can tack on a random value to the end of the url path to force a unique file name. A new date object works well.

    loader.load(new URLRequest("myfile.jpg?cachekill="+new Date()));

  3. #3
    Senior Member bluemagica's Avatar
    Join Date
    Jun 2008
    Posts
    766
    For me that works great for php, as it worked in as2, actually i like to use Date().getTime(), but when i use it for images, sometimes the image fails to load!

  4. #4
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    The image will fail to load when testing locally, but when it's running on a server it will work just fine.

  5. #5
    AKA [ Paul Bainbridge] webdreamer's Avatar
    Join Date
    Aug 2001
    Location
    Glasgow, Scotland, UK
    Posts
    3,317
    Quote Originally Posted by bluemagica
    For me that works great for php, as it worked in as2, actually i like to use Date().getTime(), but when i use it for images, sometimes the image fails to load!
    I also use . "?rand="+new Date().getTime()
    .: To me AS is like LEGO, Only for the big Kids :.
    - Site - Blog - Twitter - Linkedin
    bringmadeleinehome.com

  6. #6
    Senior Member bluemagica's Avatar
    Join Date
    Jun 2008
    Posts
    766
    Since my entire movie relies heavily on php communication, i have to run it on my local WAMP server to see it! And even in this stage, the loading of external sometimes fail when i use the unique url method!

  7. #7
    AKA [ Paul Bainbridge] webdreamer's Avatar
    Join Date
    Aug 2001
    Location
    Glasgow, Scotland, UK
    Posts
    3,317
    Are you direct linkiing to the files(http://www) or locally linking(somefolder/image.jpg)?
    .: To me AS is like LEGO, Only for the big Kids :.
    - Site - Blog - Twitter - Linkedin
    bringmadeleinehome.com

  8. #8
    Senior Member bluemagica's Avatar
    Join Date
    Jun 2008
    Posts
    766
    locally linked

  9. #9
    Junior Member
    Join Date
    Jan 2010
    Location
    Karlstad, Sweden
    Posts
    4
    I prefer the method described here: http://www.ultrashock.com/forums/act...s3-123408.html

    Here's the interesting part of it all:
    Code:
    var req:URLRequest = new URLRequest( "media/flash/intro.swf" );
    req.method = URLRequestMethod.POST;
    req.data = true; // POST requests require non-null data
    
    var loader:Loader = new Loader();
    loader.load( req );
    Worked fine for me both locally and remotely and the use of POST instead of GET seems much tidier

  10. #10
    Junior Member
    Join Date
    Nov 2009
    Posts
    12
    Hmmm, nice idea!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center