Fully ActionScripted Preloader [Flash][Actionscript]

Started by: FrAnKeH | Replies: 35 | Views: 4,654

FrAnKeH
2

Posts: 602
Joined: Aug 2005
Rep: 91

View Profile
Apr 7, 2006 1:01 AM #7175
Make a blank keyframe at the begining of your movie and add this actionScript

ON THE FRAME
(select the frame and click F9 and paste the code in)

And then that is it.
Make sure that on frame 2 your movie starts...
Obviously this isnt ment for big scale movies but its good for tests and such.
All code created by me.
And there is no need to make any graphics.
The Actionscript does it all.



stop();
MakeBox();
Ready = false;
mouseClicked = true
_root.createTextField("percent", 2, Stage.width/4, (Stage.height/3)+50, 300, 100);
MakeText("Loading....");

function MakeBox() {
_root.createEmptyMovieClip("loadBox", 4);
loadBox.lineStyle(5, 0x000000, 100);
loadBox.moveTo(Stage.width/4, (Stage.height/3)+120);
loadBox.lineTo((Stage.width/4)+300, (Stage.height/3)+120);
loadBox.lineTo((Stage.width/4)+300, (Stage.height/3)+140);
loadBox.lineTo(Stage.width/4, (Stage.height/3)+140);
loadBox.lineTo(Stage.width/4, (Stage.height/3)+120);
}
function MakeLoadBar() {
_root.createEmptyMovieClip("loadBar", 3);
loadBar.lineStyle(20, 0xf99f99, 100);
loadBar.moveTo((Stage.width/4)+8, ((Stage.height/3)+120)+10);
loadBar.lineTo((Stage.width/4)+(percentage*2.9), ((Stage.height/3)+120)+10);
}
function MakeText(textValue) {
_root.createTextField("loading", 1, Stage.width/4, Stage.height/3, 300, 100);
textFormat = new TextFormat();
textFormat.size = "50";
_root.loading.text = textValue;
_root.loading.setTextFormat(textFormat);
}


function onEnterFrame() {
_root.percent.text = percentage+"%";
percentage = (_root.getBytesLoaded()/_root.getBytesTotal())*100;
_root.percent.setTextFormat(textFormat);
if (_root.percent.text == "100%" && Ready == false) {
MakeText("Click To Play");
Ready = true;
} else if (Ready == false) {
MakeLoadBar();
}
}
function onMouseDown() {
if (Ready == true && mouseClicked == true) {
_root.percent.removeTextField();
_root.loading.removeTextField();
loadBar.unloadMovie();
loadBox.unloadMovie();
gotoAndPlay(2);
mouseClicked = false
}
}




Note: Works best with flash player 7 and above.
Flash player 6 has font problems.
Doesnt work at all with flash 5.

Anyone can use it.
Gray
2

Posts: 926
Joined: Aug 2005
Rep: 15

View Profile
Apr 7, 2006 1:02 AM #7176
thts sexy dude, thanks!
Poutine Salad
2

Posts: 331
Joined: Aug 2005
Rep: 41

View Profile
Apr 7, 2006 1:47 AM #7184
That is really nice.
FreeAsANerd

Posts: 0
Joined: Dec 2025
Apr 7, 2006 2:07 AM #7187
Yeah, nice one, Frankeh!
Polnareff
2

Posts: 17
Joined: Nov 2005
Rep: 10

View Profile
Apr 7, 2006 3:10 AM #7189
Sexy stuff. Thumbs up for FrAnKeH...and Willy too!

Image
azam_me91
2

Posts: 742
Joined: Aug 2005
Rep: 10

View Profile
Apr 7, 2006 4:20 AM #7192
woot ima check it out tomorow....
Other³
2

Posts: 13
Joined: Sep 2005
Rep: 10

View Profile
Apr 7, 2006 8:30 AM #7196
wikcerd kul dud!

nice one.
FrAnKeH
2

Posts: 602
Joined: Aug 2005
Rep: 91

View Profile
Apr 7, 2006 1:19 PM #7204
Im gunna add a load bar as well...
Edit:
The code is getting horrid... but it works.
Now with a loading bar:

stop();
MakeBox();
Ready = false;
mouseClicked = true
_root.createTextField("percent", 2, Stage.width/4, (Stage.height/3)+50, 300, 100);
MakeText("Loading....");

function MakeBox() {
_root.createEmptyMovieClip("loadBox", 4);
loadBox.lineStyle(5, 0x000000, 100);
loadBox.moveTo(Stage.width/4, (Stage.height/3)+120);
loadBox.lineTo((Stage.width/4)+300, (Stage.height/3)+120);
loadBox.lineTo((Stage.width/4)+300, (Stage.height/3)+140);
loadBox.lineTo(Stage.width/4, (Stage.height/3)+140);
loadBox.lineTo(Stage.width/4, (Stage.height/3)+120);
}
function MakeLoadBar() {
_root.createEmptyMovieClip("loadBar", 3);
loadBar.lineStyle(20, 0xf99f99, 100);
loadBar.moveTo((Stage.width/4)+8, ((Stage.height/3)+120)+10);
loadBar.lineTo((Stage.width/4)+(percentage*2.9), ((Stage.height/3)+120)+10);
}
function MakeText(textValue) {
_root.createTextField("loading", 1, Stage.width/4, Stage.height/3, 300, 100);
textFormat = new TextFormat();
textFormat.size = "50";
_root.loading.text = textValue;
_root.loading.setTextFormat(textFormat);
}


function onEnterFrame() {
_root.percent.text = percentage+"%";
percentage = (_root.getBytesLoaded()/_root.getBytesTotal())*100;
_root.percent.setTextFormat(textFormat);
if (_root.percent.text == "100%" && Ready == false) {
MakeText("Click To Play");
Ready = true;
} else if (Ready == false) {
MakeLoadBar();
}
}
function onMouseDown() {
if (Ready == true && mouseClicked == true) {
_root.percent.removeTextField();
_root.loading.removeTextField();
loadBar.unloadMovie();
loadBox.unloadMovie();
gotoAndPlay(2);
mouseClicked = false
}
}



Edit: Ok that was the final revision, Enjoy!

Edit2: I fixed the browser probelm....
http://img136.imageshack.us/my.php?image=testresttesr7up.swf
A demo for you to see.
Gray
2

Posts: 926
Joined: Aug 2005
Rep: 15

View Profile
Apr 7, 2006 7:33 PM #7223
Quote from FrAnKeH
Im gunna add a load bar as well...
Edit:
The code is getting horrid... but it works.
Now with a loading bar:

stop();
MakeBox();
Ready = false;
mouseClicked = true
_root.createTextField("percent", 2, Stage.width/4, (Stage.height/3)+50, 300, 100);
MakeText("Loading....");

function MakeBox() {
_root.createEmptyMovieClip("loadBox", 4);
loadBox.lineStyle(5, 0x000000, 100);
loadBox.moveTo(Stage.width/4, (Stage.height/3)+120);
loadBox.lineTo((Stage.width/4)+300, (Stage.height/3)+120);
loadBox.lineTo((Stage.width/4)+300, (Stage.height/3)+140);
loadBox.lineTo(Stage.width/4, (Stage.height/3)+140);
loadBox.lineTo(Stage.width/4, (Stage.height/3)+120);
}
function MakeLoadBar() {
_root.createEmptyMovieClip("loadBar", 3);
loadBar.lineStyle(20, 0xf99f99, 100);
loadBar.moveTo((Stage.width/4)+8, ((Stage.height/3)+120)+10);
loadBar.lineTo((Stage.width/4)+(percentage*2.9), ((Stage.height/3)+120)+10);
}
function MakeText(textValue) {
_root.createTextField("loading", 1, Stage.width/4, Stage.height/3, 300, 100);
textFormat = new TextFormat();
textFormat.size = "50";
_root.loading.text = textValue;
_root.loading.setTextFormat(textFormat);
}


function onEnterFrame() {
_root.percent.text = percentage+"%";
percentage = (_root.getBytesLoaded()/_root.getBytesTotal())*100;
_root.percent.setTextFormat(textFormat);
if (_root.percent.text == "100%" && Ready == false) {
MakeText("Click To Play");
Ready = true;
} else if (Ready == false) {
MakeLoadBar();
}
}
function onMouseDown() {
if (Ready == true && mouseClicked == true) {
_root.percent.removeTextField();
_root.loading.removeTextField();
loadBar.unloadMovie();
loadBox.unloadMovie();
gotoAndPlay(2);
mouseClicked = false
}
}



Edit: Ok that was the final revision, Enjoy!

Edit2: I fixed the browser probelm....
http://img136.imageshack.us/my.php?image=testresttesr7up.swf
A demo for you to see.

bang, and the dirt is gone!

nice, i'll use this, thanks!

^_^
Pizza

Posts: 0
Joined: Dec 2025
Apr 7, 2006 7:41 PM #7225
love it!

but make gotoAndPlay(2);
to gotoAndPlay(next);
or somthing like that.

nothing besides that, its all good!
FrAnKeH
2

Posts: 602
Joined: Aug 2005
Rep: 91

View Profile
Apr 7, 2006 7:44 PM #7226
Usualy people use the preloader on the first frame..
However if you dont you can replace:
gotoAndPlay(2);
with:
gotoAndPlay(nextFrame);
Shadow801

Posts: 0
Joined: Dec 2025
Apr 10, 2006 9:12 AM #7474
Wow thats a lllloooonnnnnggg code :/ I seen a shorter one then that but in my experience longer works better lol
FrAnKeH
2

Posts: 602
Joined: Aug 2005
Rep: 91

View Profile
Apr 10, 2006 9:32 AM #7475
A shorter one where no graphics need to be made?
vertman
2

Posts: 108
Joined: Sep 2005
Rep: 9

View Profile
Apr 10, 2006 10:13 AM #7476
This is going on P2L...
The_Stranger123

Posts: 0
Joined: Dec 2025
Apr 17, 2006 2:24 PM #8015
hey guys i just gotta say that fo some reason its loading to 100% in like 1/2 second. Can any1 help me