Preloaders!

Okay ya’al have been so helpful, I thought I would ask you this one:

I have tried the tutorial on preloaders featured here on this site, and all it resulted in was turning my once seemlessly smooth movie into a strobe effect of the background.

Not exactly what I was looking to do.

So I went out on the world wide web in search of an answer. Came across an idea (since I already have my movie made), about putting your preloader into a new scene.

Well that works great, except it never loaded to my movie, it just kept replaying the loader (which wasn’t THAT exciting to watch).

Sooooo …

How to create a preloader into a new scene that will launch my actual scene once it is loaded?

Thanks in advance,
Vixie

Vixie,

I picked up a nice preloader someplace (don’t remember where), but you can cut and paste it for a try. Basically, it’s 10 frames. If you were to insert these 10 frames before any other frame in your movie (whatever frame your movie starts at would then start on frame 11), it seems to work for me every time.

Take a look if you want.

http://aspirin99.guardianhosting.net/misc/

Can you walk me through the process of putting that into my movie?

Thanks so much for your help,
Vixie

Nice pic :slight_smile:

Thanks :stuck_out_tongue:

I’ll try, but I only have a minute before I have to leave.

Open the preloader and save it to a new fla name. Open your file, click the upper left frame and drag your mouse to highlight all frames in the file.

Right click and select copy frames.

Go back to the preloader. Add a layer and paste the contents into frame 11.

I may not be around much for the next several days, someone here should be able to help if that is not clear. Good luck.

This preloader only requires one frame, a movie clip and that 1 frame must have a stop action on it, no use for new scenes!!!

OnClipEvent(enterFrame)
if(_root._framesloaded > 0 && _root._framesloaded == _root._totalframes)
gotoAndPlay(“beginMovie”)
else
//Display percentage in dynamic text box named percentoutput
percent=int(_root.getBytesLoaded()/_root.getBytesTotal() *100)
_root.percentoutput=percent + “%”

This code should work perfectly but try to recreate it in flash don’t copy from this because the punctuation is not all correct. Be sure to have that stop action on the first frame and you won’t get that strobe effect anymore. When you add a stop action it allows the flash to actually check for what you’ve asked, if theres no stop action the OnClipEvent(enterFrame) will keep looping whatever is on the first frame. I feel your pain I had such trouble with preloaders when I started, the things are evil but they help!!

Hope this helps

Kyle

Here is the error messages I received:

Scene=images, Layer=Preloader, Frame=1: Line 1: Clip events are permitted only for movie clip instances
onClipEvent (enterFrame) {

Scene=images, Layer=Preloader, Frame=1: Line 5: ‘else’ encountered without matching ‘if’
} else {

Scene=images, Layer=Preloader, Frame=1: Line 7: ‘;’ expected
percent=int(_root.getBytesLoaded()/_root.getBytesTotal() *100) _root.percentoutput=percent + “%” ;

Now how to fix that?

Thanks,
Vixie

Lucky you :stuck_out_tongue:

Okay so I have a main movie that loads external .swf movies upon click. I want a preloader for the external movies. Do I add the preloader code to the main movie or the external (in Frame 1)?

I tried loading it into the main movie, here is the code:

onClipEvent (enterFrame) {
if ( _root._framesloaded > 0 && _root._framesloaded == _root.totalfames)
gotoAndPlay(“KitchenMovie.swf”);
else (percent=int(_root.getBytesLoaded()/_root.getBytesTotal() *100) _root.percentoutput=percent + “%”) ;

Here is the errors I received back:

Scene=Scene 1, Layer=Kitchen Code, Frame=200: Line 7: Clip events are permitted only for movie clip instances
onClipEvent (enterFrame) {

Scene=Scene 1, Layer=Kitchen Code, Frame=200: Line 10: ‘)’ expected
else (percent=int(_root.getBytesLoaded()/_root.getBytesTotal() *100) _root.percentoutput=percent + “%”) ;

Okay brains … help me out :slight_smile:

Thanks,
Vixie

www.goldenwillowdesign.com
(if you want to see what I am talking about)

There are a few reasons why your code isn’t working, a few changes and everything will work. The reason your gettting that error message is because you can’t attach anything with an OnCLipEvent action to a frame, it must be attached to a movieclip.
The second problem with your code is this line else (percent=int(_root.getBytesLoaded()/_root.getBytesTotal() *100). The else action should be sperated like this else}
//Display percentage in dynamic text box named percentoutput
percent=int(_root.getBytesLoaded()/_root.getBytesTotal() *100).
and when your preloading a external movie you don’t want to use _root it will either be _level1,2,3 etc or a the target of a movieclip.

The code that I originally gave you is best suited to preloading a movie or movieclip that is internal or inside your main movie.
Here is the code to preload an external swf. This code should be attached to the movieclip that you are loading your external swf into.

frame 1:
loadMovieNum(“kitchenmovie.swf”, “target 1”)

Attached to target 1:
OnClipEvent(enterFrame)
if(this.getBytesTotal == undefined)
total=this.getBytesTotal)
}
loaded=this.getBytesLoaded
remaining=loaded-total
percent=int(this.getBytesLoaded()/this.getBytesTotal() * 100)
//Display in dynamic text field
_root.percentout=percent + “%”

Hope this helps

Kyle

*Originally posted by iceman *
**There are a few reasons why your code isn’t working, a few changes and everything will work. The reason your gettting that error message is because you can’t attach anything with an OnCLipEvent action to a frame, it must be attached to a movieclip.

Kyle **

Okay you have lost me. So how do I attach action script to a movieclip vs attaching it to the frame?

Can you please walk me step by step how to do this? It might clear up A LOT of problems I am having.

Thanks a ton,
Vixie

Since I already have an instance named for the button (load) action … can I just add the script to it?

kitbut.onPress = function () {
_root.createEmptyMovieClip(“container”, 1);
loadMovie(“KitchenMovie.swf”, “container”);
container._x = 10 ;
container._y = 10 ;
if(this.getBytesTotal == undefined)
//Display in dynamic text field
_root.percentout=percent + “%”
}
total=this.getBytesTotal
loaded=this.getBytesLoaded
remaining=loaded-total
percent=int(this.getBytesLoaded()/this.getBytesTotal() * 100)

Does that work?

Thanks again,
Vixie

Anyone out there who knows the answer?

Well, if you want to know whether the code works or not, just try it. But there are a few syntax errors… For instance, when you use a method, you have to put () at the end of it (getBytesTotal()…)

Anyway, if you want the code, you’d better check Supra’s tute http://www.kirupa.com/developer/mx/photogallery.asp
Basically, it should go like this:

MovieClip.prototype.loadSwf = function(swfName) {
    this.createEmptyMovieClip("holder", 1);
    this.holder.loadMovie(swfName);
    this.onEnterFrame = function() {
        if (this.holder.getBytesLoaded() > 1 && this.holder.getBytesLoaded() >= this.holder.getBytesTotal()) {
            delete this.onEnterFrame;
            }
       } else {
            trace ("Not there yet");
       }
}

// Use it like that
_root.loadSwf("KitchenMovie.swf");

This is not a tested code, so if it doesn’t work… well just tell me.

pom :asian:

There are a few things wrong in your code:

*Originally posted by VixenLady *

kitbut.onPress = function () {
	_root.createEmptyMovieClip("container", 1);
	loadMovie("KitchenMovie.swf", "container");
	container._x = 10 ;
	container._y = 10 ;
	**if(this.getBytesTotal == undefined)**
//Display in dynamic text field
_root.percentout=percent + "%"
}
**total=this.getBytesTotal
loaded=this.getBytesLoaded
remaining=loaded-total
percent=int(this.getBytesLoaded()/this.getBytesTotal() * 100)**

So, you create an empty movie clip, load your movie, put the clip where you want it, and… if getBytesTotal is undefined, you trace percent (???).

Errors: getBytesTotal () is relative to this aka your button, not the clip you’re loading. Then if it is undefined, you can’t display it :slight_smile: Finally, what is percent? You never defined it.

Then the last bunch of code is outside the handler :stuck_out_tongue: and you forgot () and ; everywhere.

So to correct your code a bit, you’d have to write something like

kitbut.onPress = function () {
   _root.createEmptyMovieClip("container", 1);
   loadMovie("KitchenMovie.swf", "container");
   container._x = 10 ;
   container._y = 10 ;
   loaded=_root.**container**.getBytesLoaded();
   total=_root.**container**.getBytesTotal ();
   _root.container.onEnterFrame = function() {
      if (loaded>1 and loaded==total) {
         //Display in dynamic text field
         _root.percentout="Loaded";
         this.onEnterFrame = null;
      } else {
         remaining=total-loaded;
         percent=loaded/total*100;
         _root.percentout=remaining+" kb remaining";
      }
   }
}

Still alive?:stuck_out_tongue: AS is tough… So don’t hesitate to ask if you have questions.

Cheers.

pom :asian:

That all made sense and I added the correct code. No errors :slight_smile:

BUT, no preloader displays.

I am wondering if it is because I have not taken the step to add any sort of dynamic text field.

AHHH I am so lost,
Vixie

I have added a dynamic text box to my main .swf … I set all the settings and I need to add a “var” name to it, right?

What “var” name do I give it based on the code above?

Thanks
Vixie

All the code samples make sense. And I have 3 different preloaders working.

But I have one loading an external swf and I don’t want the swf to play immediately, I am trying have a button appear. Then when you hit ,all preload components go away and main swf starts.

Please see
My script

Please help.

RR

>Vixen:If you use the first code I gave, there’s no output when the movie’s loaded. But if you use my “correction”, then you have to put a textbox which VAR is <i>percentout</i>.

But beware, if you test in on your computer, the loading takes virtually no time, so you’ll have to test in on the net to see if the preloader works.

>3D:I answered in your thread.

pom :asian:

Okay since you are so nice to me … help me through what I did wrong (cuz it doesn’t work)

I used the “correction” code. Then added a new layer with a dynamic text box on the final frame with the “var” name: percent out.

I have not modified any of the correction code execpt these two lines to make sense for the code applied to the insance:

officebut.onPress = function () {
loadMovie(“OfficeMovie.swf”, “container”);

I just modified the instance name and then what file to load … other then that I kept the code as is.

When tested on the net (and even cleared all cashe to make sure nothing was being stored) I get the delay (while file is being loaded) and no preloader message :frowning:

I don’t know how to attach the flash file so you can see what I am talking about … so any help you can give me would be greatly appreciated in all this.

Thanks a ton!!
Vixie

Err… first thanks for the kind word. And second, I’d rather have a look at the fla. To attach them, you just have to zip them and then there’s a button “attach file” under the reply textbox.

cheers

pom :asian: