Actionscript: avoid loading the same file twice

thotalg

New Member
Messages
2
Reaction score
0
Points
0
Greetings, i hope this is the right place for this question.


i'm working on a flash project that Loades lots of movieClips onto the main movie depending on the user choise.

Right now i'm working under a Mac and use Safari for most of my tests and i hafond that when ever my flash needs to load again a previusly loaded clip instead of just grab the already loaded one loaded another instance of the file, this turns out into a problem 'cos after a minute of user experience the "activity list" tells me i have about 158 files loaded when i'm actually using only around 20.

I supose it has to do with my method to load them (the clasic one on action script)

onClick {
loadMovieClip('clipURL', 'targetClip');
}

if it was just matter of keep the list small, well, no problem... but it keeps loading and loading the memory of the sistem and, after a few trial i made on windows and mac, the page turns to consume so much resouces of the sistem that makes it unstable, some times it even crashes the sistem (specially when u keep clicking and loading the same clip again and again).

i've read that on php exist a couple of functions called "include_once" and "require_once" that "loads" a page or script on the "stage" only once, and if is required to be loaded again it takes the same that was included before, php.netexplains that is to avoid overloading the systems, to reduce bandwidth use and avoid renaming functions or re-declaring important stuff(not sure bout what "stuff")

so, my question would be, is there something like php's include_once on actionScript?

if not, how can i avoid expend my bandwidth loading again and agoin a new instance of the same file?

take NOTICE that i'm working on a 100% dynamic flash site, most of the content is loaded on runtime and very few elements are static as the flash plays.

(sorry about the "part naming" i use, using so much flash changes the way one name things)

Thanks a lot in advance
 

xav0989

Community Public Relation
Community Support
Messages
4,467
Reaction score
95
Points
0
you could cache the movies, or preload them
 

thotalg

New Member
Messages
2
Reaction score
0
Points
0
you could cache the movies, or preload them

PRELOAD: tryed already, seems the error is on the way i call the loading cos, even if i preload the clips the activity list on safari tells me that it keeps loading the same movie clip once and again spending bandwidth and memory.

same aplies to the caheing the clips
 

VPmase

New Member
Messages
914
Reaction score
1
Points
0
If I'm right, the loadMovieClip returns a true or false value.
So just make a var on the layer (we'll call it loadedmc:Boolean = new Boolean; loadedmc = false; //make it and set it to false) and add this to the code

Code:
onClick {
if(!_root.loadedmc){
_root.loadedmc = loadMovieClip('clipURL', 'targetClip');
}
}
 

johnbeeby

New Member
Messages
8
Reaction score
0
Points
0
on (release) {
loadMovieClip('clipURL', 'targetClip');
unloadMovieClip('URL', '_target');
}

Its best to un-include where possible. Just list all the clips you want to unload. If they are cached they will load immediately next time they are called.

Unless I totally missed the point of this, I think its a simple means of un-including files or else they will play and play and play and can be loaded on top of each other over and over without specific direction of unloadMovieClip.
 
Top