Welcome, Guest. Please login or register.
Did you miss your activation email?
05/21/12, 04:23
Home Help Search Login Register
News: Parsley Flex framework review featuring quiz application, in our Flex frameworks series
Flex SDK 4.5 mobile roadmap: begin with your mobile development
Swiz Flex framework review featuring quiz application
New homepage we release our new Homepage, take a look ...

+  Flash-db
|-+  General
| |-+  Flash 8 (Moderators: Jorge Solis, ..:: Mazhar Hasan ::.., Andresss)
| | |-+  preloader - how to make sure files totally loaded before it start play?
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] 2 Print
Author Topic: preloader - how to make sure files totally loaded before it start play?  (Read 4942 times)
-shamarque-
Jr. Programmer
**
Posts: 53

shamarque@hotmail.com shamarque@yahoo.com shamarque
View Profile WWW Email
« on: 08/07/06, 00:55 »

Hi all...

I below here is my script. My problem is, i would like to make sure that intro.swf totally load first before it start.

What i have here is, the intro.swf files loads around 50% then its already played. I want it to be totally loaded (100%) before its start play.

Is any code that i should add?

Code:
loadMovie("intro.swf", "mc_hold");
_root.mc_hold._x = 0;
_root.mc_hold._y = 0;
function preload(mc_hold) {
if (!mc_hold.doneLoading) {
if (mc_hold._framesloaded>0 && mc_hold._framesloaded == mc_hold._totalframes) {
mc_hold.doneLoading = true;
gotoAndPlay(2);
}
Loaded = mc_hold.getBytesLoaded();
Total = mc_hold.getBytesTotal();
var Slash = mc_hold._url.lastIndexOf("/");
Movie = mc_hold._url.substring(Slash+1, mc_hold._url.length);
var percentLoaded = (mc_hold.getBytesLoaded()/mc_hold.getBytesTotal());
Width._width = WidthMeasure._width*percentLoaded;
}
}
stop();

Thank you in advance.
Logged

-Success Is A Ladder That Cannot Be Climbed With Your Hands In Your Pocket-
-shamarque-
Jr. Programmer
**
Posts: 53

shamarque@hotmail.com shamarque@yahoo.com shamarque
View Profile WWW Email
« Reply #1 on: 08/07/06, 01:44 »

on the mc_hold.. i've this script.

Code:
onClipEvent (enterFrame) {
  if (this._url != _root._url) {
    _root.preload(this);
  }
 
}
Logged

-Success Is A Ladder That Cannot Be Climbed With Your Hands In Your Pocket-
-shamarque-
Jr. Programmer
**
Posts: 53

shamarque@hotmail.com shamarque@yahoo.com shamarque
View Profile WWW Email
« Reply #2 on: 08/07/06, 21:56 »

anyone could help me?
Logged

-Success Is A Ladder That Cannot Be Climbed With Your Hands In Your Pocket-
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14600


View Profile
« Reply #3 on: 08/08/06, 01:36 »

Change this line niside preload function and test:

if (mc_hold.getBytesLoaded()>0 && mc_hold.getBytesLoaded() >= mc_hold.getBytesTotal())

Jorge
Logged

-shamarque-
Jr. Programmer
**
Posts: 53

shamarque@hotmail.com shamarque@yahoo.com shamarque
View Profile WWW Email
« Reply #4 on: 08/08/06, 02:20 »

thanks jorge...

i already tried that too jorge.. it aint working.

Code:
loadMovie("intro.swf", "mc_hold");
_root.mc_hold._x = 0;
_root.mc_hold._y = 0;
function preload(mc_hold) {
if (!mc_hold.doneLoading) {
//if (mc_hold._framesloaded <= 100 && mc_hold._framesloaded == mc_hold._totalframes) {
if (mc_hold.getBytesLoaded()>= 100 && mc_hold.getBytesLoaded() == mc_hold.getBytesTotal())
                                //if (mc_hold.getBytesLoaded()>0 && mc_hold.getBytesLoaded() >= mc_hold.getBytesTotal())
//if (mc_hold.getBytesLoaded == mc_hold.getBytesTotal) {
//if (percentLoaded=100){
gotoAndPlay(2);
mc_hold.doneLoading = true;

}
Loaded = mc_hold.getBytesLoaded();
Total = mc_hold.getBytesTotal();
Percent = Math.round(mc_hold.getBytesLoaded()/mc_hold.getBytesTotal()*100);
//var Slash = mc_hold._url.lastIndexOf("/");
//Movie = mc_hold._url.substring(Slash+1, mc_hold._url.length);
var percentLoaded = (mc_hold.getBytesLoaded()/mc_hold.getBytesTotal());
Barra._width = BarraMoldura._width*percentLoaded;
}
//}
stop();


for mc_hold movie clip, i have this script.

Code:
onClipEvent (enterFrame) {
  if (this._url != _root._url) {
    _root.preload(this);
  }
 
}


help me..  Cry Cry
Logged

-Success Is A Ladder That Cannot Be Climbed With Your Hands In Your Pocket-
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14600


View Profile
« Reply #5 on: 08/08/06, 02:27 »

Two possible errors

- The value are incorrect, instead of show a percentage, shows loaded and total to check if they're fine
- Something else is playing the movie (the onEnterFrame in the loaded movie keeps running)

Using an onEnterFrame from the loaded movie is really a bad idea (especially because it never stops), use the usual technique, where the function runs his own onEnterFrame to preload any movie passed as argument

Jorge
Logged

-shamarque-
Jr. Programmer
**
Posts: 53

shamarque@hotmail.com shamarque@yahoo.com shamarque
View Profile WWW Email
« Reply #6 on: 08/08/06, 02:34 »

hi jorge..

thanks again..

i already check the values.. everything was fine.

i think its because of the onEnterframe. would u suggest anything that i could use to change it? i'm sorry, quite newbie in flash thingy. If you could explain a lil bit more i really appreciate. If u could give me any other sources that i could refer or learn bout it, i much more appreciate.

actually i'm running out of time... my boss keep looking at me & mailing me asking me bout this preloader thingy.

by the way, thanks a lot jorge..
Logged

-Success Is A Ladder That Cannot Be Climbed With Your Hands In Your Pocket-
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14600


View Profile
« Reply #7 on: 08/08/06, 02:46 »

Modify like this:

function preload(whomc_hold) {
	
mc_hold.loadMovie(who)
	
this.onEnterFrame = function(){
	
	
Loaded mc_hold.getBytesLoaded();
	
	
Total mc_hold.getBytesTotal();
	
	
Percent Math.round(mc_hold.getBytesLoaded()/mc_hold.getBytesTotal()*100);
	
	
var 
percentLoaded = (mc_hold.getBytesLoaded()/mc_hold.getBytesTotal());
	
	
Barra._width BarraMoldura._width*percentLoaded;
	
	
if (
Loaded>&& Loaded >= Total) {
	
	
	
gotoAndPlay(2);
	
	
	
delete this.onEnterFrame
	
	
}
	
}
}
preload("some.swf"some_holder)
stop()

Delete the onClipEvent thing from the loaded Movie. Where I put "some.swf" use the name of your movie, where I put some_holder use the instance name of the MovieClip where you want to load the movie

Jorge
Logged

-shamarque-
Jr. Programmer
**
Posts: 53

shamarque@hotmail.com shamarque@yahoo.com shamarque
View Profile WWW Email
« Reply #8 on: 08/08/06, 02:58 »

what does it means by "who" jorge?

anyway thank you in advance jorge
Logged

-Success Is A Ladder That Cannot Be Climbed With Your Hands In Your Pocket-
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14600


View Profile
« Reply #9 on: 08/08/06, 03:28 »

The first argument of the function:

preload("some.swf", someClipIhaveOnStage)

so who becomes ->"some.swf" (first argument)
some_holder becomes-> someClipIhaveOnStage

You pass values, the function use this values, doesn't matter the variable name. This is one of the principles of reusability, and some of the reasons that make function usefull

Jorge

Logged

-shamarque-
Jr. Programmer
**
Posts: 53

shamarque@hotmail.com shamarque@yahoo.com shamarque
View Profile WWW Email
« Reply #10 on: 08/08/06, 03:56 »

something like this jorge?

Code:
function preload("intro.swf", mc_hold) {
mc_hold.loadMovie("intro.swf")
this.onEnterFrame = function(){
Loaded = mc_hold.getBytesLoaded();
Total = mc_hold.getBytesTotal();
Percent = Math.round(mc_hold.getBytesLoaded()/mc_hold.getBytesTotal()*100);
var percentLoaded = (mc_hold.getBytesLoaded()/mc_hold.getBytesTotal());
Barra._width = BarraMoldura._width*percentLoaded;
if (Loaded>3 && Loaded >= Total) {
gotoAndPlay(2);
delete this.onEnterFrame
}
}
}
preload("intro.swf.swf", mc_hold)
stop()
Logged

-Success Is A Ladder That Cannot Be Climbed With Your Hands In Your Pocket-
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14600


View Profile
« Reply #11 on: 08/08/06, 04:32 »

No my friend. Don't touch the function, just copy&paste as I have writed. Imagine that I want to load "intro.swf" inside a MovieClip with instance name "holder_mc", I will use:

preload("intro.swf", holder_mc)

Now imagine that I want to load "home.swf" inside a MovieClip with instance name "another_holder_mc", I will use:

preload("home.swf", another_holder_mc)

And so on ... the function remains always the same.

Jorge
Logged

-shamarque-
Jr. Programmer
**
Posts: 53

shamarque@hotmail.com shamarque@yahoo.com shamarque
View Profile WWW Email
« Reply #12 on: 08/08/06, 21:06 »

owh ok.. thanks jorge..

it's not working too.. *sigh....

hmm..... you can look access it @ http://www.sesamaconsulting.com/test/test05

for fla's.. i already PM u Jorge for the url.

thank you in advance.

Logged

-Success Is A Ladder That Cannot Be Climbed With Your Hands In Your Pocket-
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14600


View Profile
« Reply #13 on: 08/09/06, 02:19 »

I don't study movies, check http://www.flash-db.com/Board/index.php?topic=13655.0
Change this line for a larger base size:

if (Loaded>10 && Loaded >= Total)

This conditions try to skip what usually happens at beginning of preloaders, that's when Flash didn't read the header of the file to load, both loaded and Total match in -1, and sometimes in low values. Another usual way is to ensure that MC have some width:

if (holder._mc.width>0 && Loaded >= Total)

Jorge
Logged

-shamarque-
Jr. Programmer
**
Posts: 53

shamarque@hotmail.com shamarque@yahoo.com shamarque
View Profile WWW Email
« Reply #14 on: 08/09/06, 03:17 »


i'm sorry jorge.. read it, digest it & respect ur point of view  Wink

wont let it happen again...


by the way. its still not working.. i'll redoit all... thanks jorge.. will update u if i can solve the problem or i get stuck again..

thanks a lot jorge
Logged

-Success Is A Ladder That Cannot Be Climbed With Your Hands In Your Pocket-
Pages: [1] 2 Print 
« previous next »
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!