00:00
00:00
Newgrounds Background Image Theme

Allthingz2020 just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

AS: _currentframe

14,470 Views | 35 Replies
New Topic Respond to this Topic

AS: _currentframe 2006-02-26 19:32:42


AS: Main

AS: _currentframe

This is a very basic introduction to the _currentframe property used in Flash (mainly games) all the time.

Okay, so what are we going to learn about today?

Today, we're going to learn about the _currentframe property. The _currentframe property is an action used in Flash that specifys a certain frame number of something. The _currentframe property can be used to specify a certain frame number in a Movie Clip, or a certain frame in the Main Timeline! It is a very and I mean very handy piece of Actionscript.

Alright, so I know what it does now, but how do I use it?

Well, let's say, for example, you wanted to find out if the frame of a Movie Clip was on frame 25. Let's start by opening a new Flash document. Draw a basic square and convert it into Movie Clip(Highlight the Movie Clip>>Right Click>>Convert to Symbol>> Movie Clip). When you are in the Movie Clip, give it about 50 or so frames. Now go back to Scene 1 of your Flash and give the Movie Clip an instance name of "my_mc" without the quotes.

Now go to your main timeline and put these actions on it:
onEnterFrame=function(){
if(_root.my_mc._currentframe==25){
trace("The MC has reached the 25th frame");
}
}

So now let's break that code down:
onEnterFrame=function(){ //For every frame on the Flash document...
if(_root.my_mc._currentframe==25){ // if the Movie Clip "my_mc" reaches 25...
trace("The MC has reached the 25th frame"); //tells flash to tell the output box to say "The MC has reached the 25th frame"
} //end if
} //end onEnterFrame

Now, before we go any further let me clarify one thing.
Many people do not know the difference between = and ==
Well here is the difference between the two:
= is used to define something (i.e score=2, health=100, n00bs=1000 etc.)
== is used in everything else, mainly if statements(i.e if(score==2), if(health==100), if(n00bs==1000))

So now that that's cleared up we can finally move on...

How can this help me to make a game?

Let's see. The _currentframe property can be used to tell something to do something. For example:

if(_root.enemy._currentframe==5){
_root.player.gotoAndStop("Pee_Pants")
}

That says that "if the Movie Clip 'enemy' is on frame 5, then the Movie Clip 'player' goes to the frame 'Pee_Pants' where in this case the player would be pissing his pants! har har har... anyway...

The _currentframe property can also be mixed with other things, such as variables. For example:

i=0
onEnterFrame=function(){
if(_root.i=0 && _root.MC._currentframe==2){
_root.MC.play();
}
}

That is saying that "if the variable 'i' is equal to 0 AND the Movie Clip 'MC' is on frame 2, then the Movie Clip 'MC' plays"

Hmm that all makes sense, but what if I want something to continuously happen after a certain frame?

This is where the > and < signs come in. These two signs mean greater than and less than
> - greater than
< - less than

How are they used in the _currentframe property?

Well let's say you wanted to say this:
"if the Movie Clip 'MC' is greater than 5, the Movie Clip 'MC2' plays"

You would put:

onEnterFrame=function(){
if(_root.MC._currentframe>5){
_root.MC2.play();
}
}

Now this is something you all MUST learn. In the code above, it says that "if the Movie Clip 'MC' is greater than 5..." This means that if it is on frame 5, nothing will happen...at all. >5 would state that it is greater than 5, meaning... not 5 at all, but greater than it, meaning 6 or above. Many people get this confused and it needs to be understood.

Well what about if I wanted something to happen on frame 5 or greater than frame 5?
These are where the > or < signs and the = sign combine. Let's give an example before we get to into it:
onEnterFrame=function(){
if(_root.MC._currentframe<=5){
_root.MC2.play();
}
}

Now that one is saying that "if the Movie Clip 'MC' is less than or equal to 5, the Movie Clip 'MC2' will play"
<= would specify that if the frame is less than OR equal to, meaning that if it ranges from 1-4 OR is on frame 5, than the Movie Clip "MC2" plays.

Wow, that is a lot to remember! Is there anything else I need to know?

Yep! As much as it may be to remember, there is still more! And there it is! There it is again!!! There it is 3 times! What the hell am I talking about?? (no that is not it)

I'm talking about this ! Yep, the exclemation point This is used in not only the _currentframe property, but in defining variables, hitTests, and much much more. The exclemation point is used to say "NOT" Now you are probably wondering how it is used... Let's give an example!
onEnterFrame=function(){
if(_root.MC._currentframe!=3){
trace("_root.MC does not equal 3")
}
}

That says that "if the Movie Clip 'MC' is NOT equal to (on) frame 3, then trace the sentance '_root.MC does not equal 3' "

It is ALWAYS used next to an = sign where the two signs > and < do not HAVE to be.

Uhhnnn my head...so much stuff!!

Well, the best advice I can give is to read it each day, or experement a bit each day until you come to finally understand it perfectly. It is a property that is used ALL the time in Flash, mainly games...

So that is it with the _currentframe property. I hope you all learned a lot, it took me a long ass time to write =P

Response to AS: _currentframe 2006-02-26 19:36:40


a whole AS thread on...._currentframe? :S

maybe it's me, but that doesn't seem right.


snyggys

Response to AS: _currentframe 2006-02-26 19:37:59


At 2/26/06 07:36 PM, 2k_rammerizkool wrote: a whole AS thread on...._currentframe? :S

maybe it's me, but that doesn't seem right.

Yeahhh sure why not!? There is a tutorial one everything else, at least have one on _currentframe =P

Response to AS: _currentframe 2006-02-26 19:49:22


haha, that is why I wrote this tut =P

Response to AS: _currentframe 2006-02-26 19:58:27


At 2/26/06 07:49 PM, True_Darkness wrote: haha, that is why I wrote this tut =P

while you're at it, write a tutorial on what program you use to make flash.


snyggys

Response to AS: _currentframe 2006-02-26 20:12:48


At 2/26/06 07:58 PM, 2k_rammerizkool wrote:
At 2/26/06 07:49 PM, True_Darkness wrote: haha, that is why I wrote this tut =P
while you're at it, write a tutorial on what program you use to make flash.

That my friend has been done by -Evan-, but I'm too lazy to look for his FAQ on it

Response to AS: _currentframe 2006-02-26 22:01:05


Comments appreciated =D

Response to AS: _currentframe 2006-02-26 22:03:59


At 2/26/06 07:58 PM, 2k_rammerizkool wrote: while you're at it, write a tutorial on what program you use to make flash.

or make a tutorial on how to read. Thatd be interesting.

Response to AS: _currentframe 2006-02-26 22:22:06


At 2/26/06 10:07 PM, Khao wrote: stop making all these AS thread about useless shits already covered in other thread! >:(

lol sorry for trying to help people...

Response to AS: _currentframe 2006-02-26 22:36:09


At 2/26/06 10:27 PM, Khao wrote:
At 2/26/06 10:22 PM, True_Darkness wrote:
At 2/26/06 10:07 PM, Khao wrote: stop making all these AS thread about useless shits already covered in other thread! >:(
lol sorry for trying to help people...
haven't you seen denvish's post in AS:main asking to stop doing useless AS threads and start working on more advanced never-been-done-before threads like more OOP, or bitmapdatas and all these things that aren,t covered yet because it takes him a few hours updating the list and he has to do it often

I actually didn't read that post sorry. I really don't think this is useless though, _currentframe is like...the BIGGEST thing in gameing. Well not the biggest but I use it SOOOOO much, and I couldn't believe there was no tut on it, I had to made an in depth one cause this is very very important...

Response to AS: _currentframe 2006-02-26 22:40:13


At 2/26/06 10:36 PM, True_Darkness wrote: I actually didn't read that post sorry. I really don't think this is useless though, _currentframe is like...the BIGGEST thing in gameing.

I have never used it in a single one of my games......but ya, unless its something new and origonal, then Denvish prefers it not posted.


BBS Signature

Response to AS: _currentframe 2006-02-26 22:41:22


At 2/26/06 10:40 PM, 23450 wrote:
I have never used it in a single one of my games......but ya, unless its something new and origonal, then Denvish prefers it not posted.

alright alright fine. No more shitty AS threads from me =P
But I'm still surprised you've never used _currentframe. Although you can just use variables instead of it but still...

Response to AS: _currentframe 2006-05-28 18:30:16


No problem. I hope it helps. I know a lot of people thought it was extremely beginnerish but I know that a lot of people could actually use it! I hope it does help with whatever you might be having trouble on =)

Response to AS: _currentframe 2006-07-01 14:58:00


i would like to thank true darkness for making this it really helped me as i am a true begginer

Response to AS: _currentframe 2006-07-09 10:42:51


You forgot that if you want to SET _currentframe, you can't just say

_currentframe = 5;

You have to use gotoAndStop();

my_mc.gotoAndStop(_currentframe + 5);

Response to AS: _currentframe 2006-07-09 12:12:05


At 7/9/06 10:42 AM, Snubby wrote: You forgot that if you want to SET _currentframe, you can't just say

_currentframe = 5;

You have to use gotoAndStop();

my_mc.gotoAndStop(_currentframe + 5);

Yeah that would be pretty useful to add in too.

Response to AS: _currentframe 2006-07-09 12:21:27


I was also going to say that the _currentframe function is read only, but someone beat me. I found out it was read only the hard way, after hundreds of exports and hundreds of failures.

Response to AS: _currentframe 2006-07-20 17:54:30


At 7/9/06 12:21 PM, MLproductions wrote: I was also going to say that the _currentframe function is read only, but someone beat me. I found out it was read only the hard way, after hundreds of exports and hundreds of failures.

Muahahah that someone was ME! In your face!

Response to AS: _currentframe 2006-11-19 13:10:07


Despite all that was said here, i found this thread very helpful
thank ya TrueDarkness

Response to AS: _currentframe 2006-11-19 16:18:07


At 11/19/06 01:10 PM, FogOut9921 wrote: Despite all that was said here, i found this thread very helpful
thank ya TrueDarkness

De nada :)

Response to AS: _currentframe 2007-01-23 22:52:41


I beleive that there should be more tutorials like these. People that DO care to explain in details and holds your hand throughout the whole tutorial, but with ACTUAL examples that the "newbs" would do in flash. Don't just blurt out lines of coding and tell people that "this does whatever you want, and this goes to there, and then whatever you want" because that scares people.

I, myself, am an EXTREME newbie in ActionScript. I barely understand anything, and even though I WANT to learn, I can't because all I seem to read are topics that tells you what does what, but doesn't give you concrete examples like the help files in flash 8.

I get "scared" somewhat when I have to read a topic that has like 50 lines of coding and about 20 of explanation. please, please, PLEASE give us more details and even if it should be obvious even to the noobiest noob, give us the info anyway!

I really "hate" ActionScript now because I can't understand a single thing even if I try. hell, I can't even make a damn health bar because its AS thread isn't clear enough to me.

Response to AS: _currentframe 2007-03-18 17:48:26


Thanks so much! I hope this works coz I was trying to figure out how to make if score=10 go and play next frame but it just went and next frame on its own(probs coz it made the score =10 so it made it next frame without having to score 10), I think this might work better

Response to AS: _currentframe 2007-05-06 19:56:51


Wow. Im an AS noob, and this really helped me a lot. thank you!

Response to AS: _currentframe 2007-05-06 20:02:35


At 5/6/07 07:56 PM, ianianian1111 wrote: Wow. Im an AS noob, and this really helped me a lot. thank you!

Over a year later, I reply, no problem!! :)

Response to AS: _currentframe 2007-06-06 05:06:45


i think its good you explained it with so much detail, so people can actually learn something out of it and not just copy and paste the code and stay dumb :)

Response to AS: _currentframe 2007-12-13 00:22:58


Coooomplicated if ya ask me....but...when it comes to computer languages that aren't HTML...I'm a simpleton. :D


"No tears, please. It's a waste of good suffering."

BBS Signature

Response to AS: _currentframe 2007-12-22 01:23:00


wow thanks man!

im using this code now:D


cats

Response to AS: _currentframe 2008-04-13 10:55:59


This was useful, I really didn't know what _currentframe was before reading this, even if it is simple. I liked the way you wrote it too! Thanks


"just because idiots are great in number does not mean they're not idiots" - alicetheDroog

The Atheist Army|English Gentleman's Club

Sig censored by: SevenSeize

BBS Signature

Response to AS: _currentframe 2008-05-06 22:52:21


thanks I forgot how to write

_currentframe != w/e

TY

Response to AS: _currentframe 2008-06-05 18:16:51


At 2/26/06 07:32 PM, TrueDarkness wrote: AS: Main

AS: _currentframe

Now, before we go any further let me clarify one thing.
Many people do not know the difference between = and ==
Well here is the difference between the two:
= is used to define something (i.e score=2, health=100, n00bs=1000 etc.)
== is used in everything else, mainly if statements(i.e if(score==2), if(health==100), if(n00bs==1000))

So now that that's cleared up we can finally move on...

How can this help me to make a game?

Let's see. The _currentframe property can be used to tell something to do something. For example:

if(_root.enemy._currentframe==5){
_root.player.gotoAndStop("Pee_Pants")
}

That says that "if the Movie Clip 'enemy' is on frame 5, then the Movie Clip 'player' goes to the frame 'Pee_Pants' where in this case the player would be pissing his pants! har har har... anyway...

is there any way i could get an example fla. i keep trying stuff and nothing happens i think i am missunderstanding the whole thing and a little visual might help


Chea

BBS Signature