Be a Supporter!

AS: _currentframe

  • 10,148 Views
  • 45 Replies
New Topic Respond to this Topic
TrueDarkness
TrueDarkness
  • Member since: Aug. 31, 2004
  • Offline.
Forum Stats
Member
Level 27
Blank Slate
AS: _currentframe 2006-02-26 19:32:42 Reply

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

Rammer
Rammer
  • Member since: Jun. 8, 2003
  • Offline.
Forum Stats
Member
Level 33
Programmer
Response to AS: _currentframe 2006-02-26 19:36:40 Reply

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

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


snyggys

TrueDarkness
TrueDarkness
  • Member since: Aug. 31, 2004
  • Offline.
Forum Stats
Member
Level 27
Blank Slate
Response to AS: _currentframe 2006-02-26 19:37:59 Reply

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

Pyromaniac
Pyromaniac
  • Member since: Jan. 14, 2005
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to AS: _currentframe 2006-02-26 19:38:01 Reply

Wow. Something so detailed over something relitivly simple. I hate to tell you, but I think some1 has already done this, but not as detailed as you, so I guess you win. Now go out there and link that person who needed current frame help.

TrueDarkness
TrueDarkness
  • Member since: Aug. 31, 2004
  • Offline.
Forum Stats
Member
Level 27
Blank Slate
Response to AS: _currentframe 2006-02-26 19:49:22 Reply

haha, that is why I wrote this tut =P

Rammer
Rammer
  • Member since: Jun. 8, 2003
  • Offline.
Forum Stats
Member
Level 33
Programmer
Response to AS: _currentframe 2006-02-26 19:58:27 Reply

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

TrueDarkness
TrueDarkness
  • Member since: Aug. 31, 2004
  • Offline.
Forum Stats
Member
Level 27
Blank Slate
Response to AS: _currentframe 2006-02-26 20:12:48 Reply

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

TrueDarkness
TrueDarkness
  • Member since: Aug. 31, 2004
  • Offline.
Forum Stats
Member
Level 27
Blank Slate
Response to AS: _currentframe 2006-02-26 22:01:05 Reply

Comments appreciated =D

Blaze
Blaze
  • Member since: Aug. 4, 2005
  • Offline.
Forum Stats
Member
Level 22
Programmer
Response to AS: _currentframe 2006-02-26 22:03:59 Reply

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.

Khao
Khao
  • Member since: Sep. 20, 2003
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to AS: _currentframe 2006-02-26 22:07:52 Reply

stop making all these AS thread about useless shits already covered in other thread! >:(

TrueDarkness
TrueDarkness
  • Member since: Aug. 31, 2004
  • Offline.
Forum Stats
Member
Level 27
Blank Slate
Response to AS: _currentframe 2006-02-26 22:22:06 Reply

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...

Khao
Khao
  • Member since: Sep. 20, 2003
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to AS: _currentframe 2006-02-26 22:27:16 Reply

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

TrueDarkness
TrueDarkness
  • Member since: Aug. 31, 2004
  • Offline.
Forum Stats
Member
Level 27
Blank Slate
Response to AS: _currentframe 2006-02-26 22:36:09 Reply

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...

Khao
Khao
  • Member since: Sep. 20, 2003
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to AS: _currentframe 2006-02-26 22:39:06 Reply

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. 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...

I use _currentframe just a little.. maybe you're just weird.. maybe you script your things in an uneficient (sp¿) way!
lol
so yeah.. a whole thread about a property who just returns a number is like.. REALLY pointless! and I'm sure there's a tutorial about MovieClip's variables that explains _currentframe with just 5 lines of text and it tells everything that needs to be told about _currentframe

23450
23450
  • Member since: May. 28, 2003
  • Offline.
Forum Stats
Supporter
Level 27
Blank Slate
Response to AS: _currentframe 2006-02-26 22:40:13 Reply

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
TrueDarkness
TrueDarkness
  • Member since: Aug. 31, 2004
  • Offline.
Forum Stats
Member
Level 27
Blank Slate
Response to AS: _currentframe 2006-02-26 22:41:22 Reply

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...

TrueDarkness
TrueDarkness
  • Member since: Aug. 31, 2004
  • Offline.
Forum Stats
Member
Level 27
Blank Slate
Response to AS: _currentframe 2006-05-28 18:30:16 Reply

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 =)

XIIIthSoundsSoldier
XIIIthSoundsSoldier
  • Member since: Feb. 21, 2005
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to AS: _currentframe 2006-07-01 14:58:00 Reply

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

Snubby
Snubby
  • Member since: Dec. 4, 2004
  • Offline.
Forum Stats
Member
Level 21
Game Developer
Response to AS: _currentframe 2006-07-09 10:42:51 Reply

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);

TrueDarkness
TrueDarkness
  • Member since: Aug. 31, 2004
  • Offline.
Forum Stats
Member
Level 27
Blank Slate
Response to AS: _currentframe 2006-07-09 12:12:05 Reply

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.

DingoEatingFuzz
DingoEatingFuzz
  • Member since: Jun. 18, 2005
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to AS: _currentframe 2006-07-09 12:21:27 Reply

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.

Snubby
Snubby
  • Member since: Dec. 4, 2004
  • Offline.
Forum Stats
Member
Level 21
Game Developer
Response to AS: _currentframe 2006-07-20 17:54:30 Reply

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!

FogOut9921
FogOut9921
  • Member since: Sep. 16, 2006
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to AS: _currentframe 2006-11-19 13:10:07 Reply

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

TrueDarkness
TrueDarkness
  • Member since: Aug. 31, 2004
  • Offline.
Forum Stats
Member
Level 27
Blank Slate
Response to AS: _currentframe 2006-11-19 16:18:07 Reply

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 :)

AMOE1st
AMOE1st
  • Member since: Jan. 9, 2007
  • Offline.
Forum Stats
Member
Level 04
Blank Slate
Response to AS: _currentframe 2007-01-23 22:52:41 Reply

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.

SNARE
SNARE
  • Member since: May. 14, 2004
  • Offline.
Forum Stats
Member
Level 25
Blank Slate
Response to AS: _currentframe 2007-03-18 17:48:26 Reply

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

ianianian1111
ianianian1111
  • Member since: Dec. 4, 2006
  • Offline.
Forum Stats
Member
Level 22
Blank Slate
Response to AS: _currentframe 2007-05-06 19:56:51 Reply

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

TrueDarkness
TrueDarkness
  • Member since: Aug. 31, 2004
  • Offline.
Forum Stats
Member
Level 27
Blank Slate
Response to AS: _currentframe 2007-05-06 20:02:35 Reply

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!! :)

schbabaggo
schbabaggo
  • Member since: May. 26, 2007
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to AS: _currentframe 2007-06-06 05:06:45 Reply

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 :)

Voxphile
Voxphile
  • Member since: Nov. 16, 2007
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to AS: _currentframe 2007-12-13 00:22:58 Reply

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