PDA

View Full Version : Cache problems



Phryx
May 3rd, 2005, 11:06 AM
Hey all!
I have a main movie that loads different .swf files into the main movie. The problem is that I update my site once a month and because of that I have experienced some cache problems. If I change a movie called "x.swf" with a different movie also called "x.swf" the internet explorer will automaticly look for a file called "x.swf" in the cache, and if the website has been loaded once, the next time that it's loaded you wont be able to load the new "x.swf" - same filename, different content.

I've found this toutorial on Kirupa.com, but can't figure where to place the actionscript. Should it be placed at the start of every .swf file that is loaded to the main movie? Should it only be placed in the first or last frame of the main movie?

Hope you can help me out with this one... Thank you.


Underneath is the toutorial found on Kirupa.com:

When you load a movie, variables, or a text, what you load is put in the cache of your computer by your browser. This can cause problems because if you load files, chances are that you are going to update them quite often, but Flash will look for the files in the cache, that is to say the old ones.
The solution is to load your files with a unique identifier. Example:


myIdentifier=Math.round(Math.random()*10000);
loadMovie("myAnim.swf?uniq="+myIdentifier,1);

This works also with LoadVariables, LoadMovieNum and LoadVariablesNum.

lunatic
May 3rd, 2005, 11:47 AM
I would guess that you put the code wherever you are loading in x.swf.
myAnim.swf would be the name of your external.

MacGuyver
May 3rd, 2005, 11:48 AM
Just use Firefox and hit the reload button ;)

Ok, enough flaming, you just use that code instead of whatever you're using to load your .sfw files.

Phryx
May 3rd, 2005, 05:18 PM
Hi again and thanks for the answers.

I use another actionscript to load the different movies than you might think.
I've got a "container" in the movie, and this actionscript with it:

onClipEvent (enterFrame) {
if (!loaded && this._url != _root._url) {
if (this.getBytesLoaded() == this.getBytesTotal()) {
loaded = true;
_root.transition.gotoAndPlay("opening");
}
}
}

I've also got a "transition" symbol where part of the frames are labeld "opening", that explains the .gotoAndPlay("opening"). This transition is containing an animation for "closing and open" the movie in an animated way (this prevents the movie suddently popping on stage and dissepearing from the stage when pressing another menu button). If there is something you don't get from the discription above please don't hesitate writing.

Hope I will solve this anoying cache problem. Thank you.

MacGuyver
May 4th, 2005, 08:48 AM
Yes, but it should not make a difference, as you loadMovie() before that, right?

Phryx
May 4th, 2005, 03:54 PM
Hi again,

If you could please take a look at this small toutorial http://www.kirupa.com/developer/mx/preloader_transition.htm
then you can see the actionscripts. I'm not good at actionscripts at all so I can't answer the question that you've asked me above. I hope the link that I've pasted above can help you. Thank you for your time.

Phryx
May 13th, 2005, 06:14 PM
Anybody who can give me a hand here?
This is a really big issue for me.
Thanks for your time...
:)

ghjr
May 13th, 2005, 06:28 PM
If you followed that tut, you probably have a action frame that looks something like this (maybe with different section and button names):



b1.onRelease = function() {
if (_root.section != "profile.swf") {
_root.section = "profile.swf";
_root.transition.gotoAndPlay("closing");
}
};
b2.onRelease = function() {
if (_root.section != "gallery.swf") {
_root.section = "gallery.swf";
_root.transition.gotoAndPlay("closing");
}
};
b3.onRelease = function() {
if (_root.section != "photos.swf") {
_root.section = "photos.swf";
_root.transition.gotoAndPlay("closing");
}
};


Here is an example for one of the buttons using the unique code:



b1.onRelease = function() {
if (_root.section != "profile.swf") {
myIdentifier=Math.round(Math.random()*10000);
_root.section = "profile.swf?uniq="+myIdentifier;
_root.transition.gotoAndPlay("closing");
}
};


That would be to load in a no cache version of profile.swf. Hope that works!


Cheers!

Phryx
May 14th, 2005, 12:20 PM
Hey again...
On every button on stage, I've assigned this actionscript (offcourse with different instance names etc.) - By the way.. I've got some sliding effects going on to if you wonder about the first line of the AS:

on (rollOver) {
slider.xMove = b1._x;
}
on(release){
gotoAndStop(2);
}
on (release) {
if (_root.currMovie == undefined) {
_root.currMovie = "section1";
container.loadMovie("section1.swf");
} else if (_root.currMovie != "section1") {
if (container._currentframe >= container.midframe) {
_root.currMovie = "section1";
container.play();
}
}
}

Should there be any unique identifier here??^
Then I've got a container movieclip on my stage with this AS attached to it:

onClipEvent (enterFrame) {
if (!loaded && this._url != _root._url) {
if (this.getBytesLoaded() == this.getBytesTotal()) {
loaded = true;
_root.transition.gotoAndPlay("opening");
}
}
}

And finally I've got an empty keyframe with this AS attached to it:

b1.onRelease = function() {
if (_root.section != "section1.swf") {
myIdentifier=Math.round(Math.random()*10000);
_root.section = "section1.swf?uniq="+myIdentifier;
_root.transition.gotoAndPlay("closing");
}
};
b2.onRelease = function() {
if (_root.section != "section2.swf") {
myIdentifier=Math.round(Math.random()*10000);
_root.section = "section2.swf?uniq="+myIdentifier;
_root.transition.gotoAndPlay("closing");
}
};
b3.onRelease = function() {
if (_root.section != "section3.swf") {
myIdentifier=Math.round(Math.random()*10000);
_root.section = "section3.swf?uniq="+myIdentifier;
_root.transition.gotoAndPlay("closing");
}
};
b4.onRelease = function() {
if (_root.section != "section4.swf") {
myIdentifier=Math.round(Math.random()*10000);
_root.section = "section4.swf?uniq="+myIdentifier;
_root.transition.gotoAndPlay("closing");
}
};
b5.onRelease = function() {
if (_root.section != "section5.swf") {
myIdentifier=Math.round(Math.random()*10000);
_root.section = "section5.swf?uniq="+myIdentifier;
_root.transition.gotoAndPlay("closing");
}
};
b6.onRelease = function() {
if (_root.section != "section6.swf") {
myIdentifier=Math.round(Math.random()*10000);
_root.section = "section6.swf?uniq="+myIdentifier;
_root.transition.gotoAndPlay("closing");
}
};

When I play the movie from my computer (CTRL + <ENTER>), I get the following error after pressing one button:

WARNING: Duplicate label, Symbol=transition, Layer=labels, Frame=43, Label=closing
Error opening URL "file:///C|/Documents%20and%20Settings/me/Documents//Homepage/section4.swf?uniq=1056 (file:///C|/Documents%20and%20Settings/me/Documents//Homepage/section4.swf?uniq=1056)"


I hope I'm not too trouble for you :cantlook:

Thanks for your time!

ghjr
May 23rd, 2005, 10:00 AM
myIdentifier=Math.round(Math.random()*10000);
container.loadMovie("section1.swf?uniq="+myIdentifier);


Seems you have a duplicate label called closing. Give one of the frames a unique label name. Is also seems that the path to section4.swf is wrong... check that out.


Chee

Seanlail
May 23rd, 2005, 10:59 AM
Hi,

I have the same problem with the caching.
I also have a main swf and then all other swf's get loaded into it.

I use this actionscript though:

loadMovie("file.swf", "instancename");

I have a menu (loaded on the first frame) that just moves the main timeline to different frames, then on each frame I have a loadmovie action.
So will it look like this:


myIdentifier=Math.round(Math.random()*10000);
loadMovie("file.swf?uniq="+myIdentifier,1, "instancename");

?

Another weird thing is that the swf's are caching only for some of the users.
I find that the users with the faster connection, are getting the cache.
Whereas the slower dial up users are seeing everything fine

Any thoughts? (thanks in advance)

HorsePlay
May 24th, 2005, 03:18 PM
hello... no actionscript help, unfortuntally...
just sharing the fustration.
I'm loading xml into a self refreshing swf that needs to be current about every minute

"ticker_latest_results.xml?rn="+new Date().getTime()+(Math.random()*100);

and it STILL doesnt work in IE. Firefox works wonderful tho.

However....
the only solution we've discovered (for now) is server based. we created a subdomain and "Enabled Content Experation" under the HTTP Header tab. so the SWF and XML is located that subdomain only, while the rest of the site is located in the main/default directory.