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?
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.
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!!
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:
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.
*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.
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()…)
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 Finally, what is percent? You never defined it.
Then the last bunch of code is outside the handler 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? AS is tough… So don’t hesitate to ask if you have questions.
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.
>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.
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
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.
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.