-
(CS4/AS2) Button code to load latest swf non cached version?
I have a button that loads guestbook.swf. As guestbook would be updated by me I would like the latest non cached version of guestbook.swf to load always.
This is the code on the button currently. What would the code look like to load the latest version from the server? You know some random number/date time stamp thing? I tried using some Googled AS2 code off the web and the button stopped working
Could someone tell me what the correct code would be and how to add it to the code I posted below?
Thanks for your time.
on (release) {
//load Movie Behavior
if(this.L == Number(this.frame)){
loadMovieNum("guestbook.swf",this.frame);
} else {
this.frame.loadMovie("guestbook.swf");
}
//End Behavior
}
-
Senior Member
Little Known Fact:
You can attach 'GET' variables when requesting any file from a web server, without any fear of breaking something or 404'ing. The GET Variable'ed page, is cached as its own page in the browser.
SO given that this is the case: What industry standard is to generate a random number and pass that as a GET Variable to the SWF.
For instance, lets say you are loading "guestbook.swf" (which in all reality should ACTUALLY be typed: "./guestbook.swf". The ./ means the hosting/current directory and path of the folder),
Just ask for: "./guestbook.swf?validation="+YOURRANDOMNUMBERHERE.
This works with versioning and for generating a 'fresh' copy of the swf.
For versioning you just call: "validation=1.0" Every time you want to access that version of the page, so you dont have the client 'redownload' the swf each and every time they go to your webpage, then when content changes in the swf- you just switch it up to "validation=1.1" and use that each time you access the page.
OR you can just forget about caching all together- and have the client redownload the swf each and everytime it is accessed. Like: "./guestbook.swf?val="+Random(99999);
Hope that is helpful. A think to keep in mind however- You can not be guarenteed that you are accessing a cached version of a swf (if you call the same address multiple times in a rot), it is up to the browser (and the users settings) how to manage the cache, however on most browsers they try to cache and keep downloading already accessed content down to a minimum.
Best of Luck!
_GK>^.^<
-
Thanks for that detailed explanation kitty. So if I take this code
"./guestbook.swf?val="+Random(99999);
then how exactly would I apply in my guestbook button code?
I tried applying it this way and tried it on the server but it did not load the guestbook.swf. Looks like I am doing something wrong?
on (release) {
//load Movie Behavior
if(this.L == Number(this.L)){
loadMovieNum("./guestbook.swf?val="+Random(99999);",this.L);
} else {
this.L.loadMovie("./guestbook.swf?val="+Random(99999);");
}
//End Behavior
}
-
Senior Member
If you run in from a web server, it should work. If not, just scratch my idea off the list.
Also I made a type-o for as2 in my original suggestion, Random should be random (no upper case letter). Sorry about that I have not really worked with as2 in years (been working mostly with as3)
Last edited by guardiankitty; 01-07-2012 at 01:20 AM.
-
Originally Posted by guardiankitty
If you run in from a web server, it should work. If not, just scratch my idea off the list.
Also I made a type-o for as2 in my original suggestion, Random should be random (no upper case letter). Sorry about that I have not really worked with as2 in years (been working mostly with as3)
Changed to lowercase r as below but still not working on server
on (release) {
//load Movie Behavior
if(this.L == Number(this.L)){
loadMovieNum("guestbook.swf?val="+random(99999);", this.L);
} else {
this.L.loadMovie("guestbook.swf?val="+random(99999 );");
}
//End Behavior
}
Without the extra code this however works. So path is correct just the extra code has some issue-
on (release) {
//load Movie Behavior
if(this.L == Number(this.L)){
loadMovieNum("guestbook.swf",this.L);
} else {
this.L.loadMovie("guestbook.swf");
}
//End Behavior
}
-
Senior Member
Originally Posted by Tina31
Changed to lowercase r as below but still not working on server
Without the extra code this however works. So path is correct just the extra code has some issue-
Woopsie doodles, I see another type-o on my end: here try it like this
Actionscript Code:
loadMovieNum("guestbook.swf?val="+random(99999), this.L);//Without the ';'
I am nothing but butter fingers tonight--- let me know if it works for you! (I should really start testing my examples =P laziness wins typically )
-GK
-
Kitty thanks for not ignoring me. It still does not seem to work. I have uploaded a test folder here.
It has three main buttons inside. One is standard without time stamp code.
The other two are with time stamp codes so that latest swf loads. One is with your code Version1 and that does not even load the swf so I can't even test if it actually loads the latest non cached swf or not :-)
The version2 loads the guestbook.swf but does not load the latest swf! I tested it on FF, IE and Safari. FF and Safari quiet often update the guestbook.swf even with the normal non stamp code button. So not sure if the Version2 is actually working as it fails consistently on IE.
Anyway here is the what the file in the folder looks like along with the code on the buttons-
Last edited by Tina31; 01-07-2012 at 08:59 AM.
-
.
Hi,
the v1 button has syntax error
this.frame.loadMovie("guestbook.swf?val="+random(9 9999)");
should be
this.frame.loadMovie("guestbook.swf?val="+random(9 9999));
extra " at the end, the movie clip now loads at least
my site/hobby: http://www.fgps.com/keith
-
Originally Posted by fruitbeard
Hi,
the v1 button has syntax error
this.frame.loadMovie("guestbook.swf?val="+random(9 9999)");
should be
this.frame.loadMovie("guestbook.swf?val="+random(9 9999));
extra " at the end, the movie clip now loads at least
my site/hobby: http://www.fgps.com/keith
BINGO!!!! That fixed V1 is consistently working on all browsers!!! Others were hit and miss on some of the browsers for some reason. I have to head out but I will update the image in few hours for anyone who gets stuck like me
-
Here is the final result of the browsers the code works on.....
V1 one works perfectly 100% of the time in all 5 browsers. V3 is good too. Thanks everyone who helped.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|