Stick Page Forums Archive

Quick and easy way to make a preloader in AS2

Started by: latranchedepain | Replies: 11 | Views: 3,050

latranchedepain
2

Posts: 185
Joined: Jul 2012
Rep: 10

View Profile
Feb 2, 2014 2:16 PM #1151538
This tutorial is to learn how to make a very simple preloader.
I'm going to explain it, so be ready to read some text !

STEP 1 : Opening Flash

Open a Flash document. You can use any version of Flash, the document just has to be in action script 2.0
Image

I'm using Flash CS6, but you can use Flash 8 as well.

STEP 2 : Making the preloader bar

You have your scene.
Now you wanna make the preloader, huh ? Well it's a basic thing. Take the rectangle tool and make a blue filled and black outlined one.
Image

Then, select the fill, JUST THE FILL, and convert it into a symbol (movie clip) that you're going to call "loadingBar" (actually, however you call it, it will work).
Image

Alright. Select your new symbol in the scene and go to properties. There, you will give an to your bar : call it "loader".
Image

Here, we want to make the loading bar going from the center.
We want to put it in a movie clip so it will be easier to copy the whole thing in your animations : click on the whole thing and create a movie clip, double click it and make a background (black rectangle). Make sure it's centered so it will be easier to fit it in your animations (if it has different dimensions).
Image

Image

STEP 3 : Action scripting !

Here we go for the third part.
Create a new layer in your preloader symbol, call it "action".
Select the first frame and type in the action pannel (F9) :
_parent.stop();
stop ();
this.onEnterFrame = function ()
{
var _loc3 = _parent.getBytesLoaded() / _parent.getBytesTotal() * 100;
loader._xscale = _loc3;
if (_loc3 == 100)
{
this.gotoAndPlay(2);
delete this.onEnterFrame;
} // end if
};

(you'll se a little "a" on the keyframe in your timeline)

Then, insert a blank keyframe and select it, in your actions pannel, type :
stop();


Take your text tool and write "PLAY" somewhere.
Image

Convert it into a BUTTON called "playButton" (or whatever).
Image

Select it, go to actions and type :
on(release) {
_parent.play();
}

Note : (release) is better than (press) because it's only when you release the click the animation starts. If it's press, it will begin just when you click. Try to click longer in the animation below.

Make the button react to the mouse ! To get that, go in your button and you'll have 4 frames in the timeline.
Image

On the first : the button itself (let it how you made it)
Image

On the second : The button when the mouse is on it (color it in blue like the bar or anything)
Image

On the third : The button when it's clicked (color it in red)
Image

On the fourth : the "hitbox" (make a rectangle on the play text)
Image

Now, in the scene, insert a blank keyframe and draw something.
Select the frame in the timeline and type in actions :
stop();


Here is what you should get :
Click to test the animation !
You'll say it's only showing the play button and it isn't loading anything, but it's because the sfw file is so small there's almost nothing to preload.
A real working preloader and better made looks LIKE DIS !

Download the .fla here.
Atomicapple
2

Posts: 1,143
Joined: Apr 2012
Rep: 10

View Profile
Feb 2, 2014 9:07 PM #1151696
Can you post a fla for flash 8?
Phosphate

Posts: 556
Joined: Jun 2013
Rep: 10

View Profile
Feb 3, 2014 6:17 AM #1151969
yeah flash 8 is the best
latranchedepain
2

Posts: 185
Joined: Jul 2012
Rep: 10

View Profile
Feb 3, 2014 8:20 AM #1152028
Quote from Atomicapple
Can you post a fla for flash 8?


Sorry, I made it on Flash CS6...
But right now I'm at school so I can't make it. I'll do as soon as possible.
Try to follow the tutorial and put it at the beginning of a long animation you made (it can be crappy as shit, it just has to be long) and open the fla with your internet browser or just host the file on fileize. You will be able to see the loading bar growing.
Of course, I actually forgot something because if you make the preloader as I say so, the bar will go from the center of the thing. I will fix something if you want it to go from the left to the right.
PS : I like your animations, you're so amazing. :D
Scarecrow
2

Posts: 9,168
Joined: Oct 2005
Rep: 10

View Profile
Feb 3, 2014 8:28 AM #1152036
what kind of name for a percentage loaded variable is "_loc3"? that's bad coding practice.

you should try and be a bit more descriptive in your variable names. you should also explain what your code is doing, to help coding beginners learn. they'll never be able to solve their own problems if they're just ignorantly copy pasting code.
latranchedepain
2

Posts: 185
Joined: Jul 2012
Rep: 10

View Profile
Feb 4, 2014 11:23 PM #1153258
Quote from Scarecrow
what kind of name for a percentage loaded variable is "_loc3"? that's bad coding practice.

you should try and be a bit more descriptive in your variable names. you should also explain what your code is doing, to help coding beginners learn. they'll never be able to solve their own problems if they're just ignorantly copy pasting code.


Well, I copied/pasted the code myself from Guz's preloader (I decompiled the swf of an animation). I saw the code and I pasted it on my preloader.
I cannot explain what is _loc3...
Scarecrow
2

Posts: 9,168
Joined: Oct 2005
Rep: 10

View Profile
Feb 5, 2014 3:54 AM #1153357
so what you're saying is, you're making a tutorial using copy pasted code and actually have no idea what you're doing

neat
SacredBlaze
2

Posts: 57
Joined: Feb 2014
Rep: 10

View Profile
Feb 5, 2014 1:18 PM #1153652
Quote from Scarecrow
so what you're saying is, you're making a tutorial using copy pasted code and actually have no idea what you're doing

neat

Uhmm, is that prohibited or illegal?
Zed
2

Posts: 11,572
Joined: Feb 2009
Rep: 10

View Profile
Feb 5, 2014 4:59 PM #1153753
It's pretty bad form if you had to use a decompiler to get it, and you ought to credit the code to the guy who wrote it. There isn't too much harm in using stuff for a preloader though. It's not like you couldn't have gotten similar code elsewhere.

For bigger things, like complicated games, people will be upset if you make their code public. Paperclip has a tutorial here somewhere about how to protect your code so that people can't get it with a decompiler.
Hewitt

Posts: 14,256
Joined: Jul 2012
Rep: 10

View Profile
Feb 6, 2014 12:51 AM #1153919
Hey Zed I gotta ask: is this some form of infractible theft offense then? Its just that it's not the first time this has happened ya know?
Zed
2

Posts: 11,572
Joined: Feb 2009
Rep: 10

View Profile
Feb 6, 2014 1:18 AM #1153938
I personally would not infract for this thread, because this code is so generic and similar stuff is so widely available that I can't imagine anyone getting upset over it. If latranchedepain had written it himself then it would probably look exactly the same but with a different name for the variable. Plus, I don't think there was any intent to do anything wrong here. If it was longer, more specialised code then it would be on a par with animation theft, although since it's less obvious to people that they're doing anything wrong I expect I would go easy on the first offence.
Hewitt

Posts: 14,256
Joined: Jul 2012
Rep: 10

View Profile
Feb 6, 2014 8:34 AM #1154120
Okay, I just wanted to clarify. I can't read or understand how common that code is so I didn't really know as well.
Website Version: 1.0.4
© 2025 Max Games. All rights reserved.