Be a Supporter!
Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
AS: ClipEvents Jul. 26th, 2005 @ 05:27 AM Reply

AS: Main , it's better than leeching code!

What is this about?

This is a very short tutorial about clip events, clip events are the most basic way for you to trigger something constantly , this is useful for movement with keys, raising stuff, setting stuff and changing stuff constantly or one time,

The 3 Magical Stages!

1)Creating a movie clip
2)Looking at the handlers themselves
3)Proper syntax

Creating a movieclip

)draw something
)select it
)go to modify->convert to symbol

Looking at the handlers themselves

There are several importent handlers:

load
enterFrame
key down

load means when the MC is loaded and ususally triggers ONCE at the start, you use load for defining functions and variables

enterFrame is what we ususally do for constant actions since the actions trigger OVER AND OVER 12 (or whatever frames per second you use) times per second... this is useful for movement health bars and much more!

keyDown is rarely used since it's alternatives, but it triggers when a key is pressed.

Proper syntax
you're probebly asking how you will make it happen, it's quite simple actually, the syntax on a movieclip's actions is

onClipEvent(handler){
//do actions
}
onClipEvent(some other handler){
//do some other actions
}

so you could do
onClipEvent(load){
this.speed=5;
}
onClipEvent(enterFrame){
this._x+=this.speed;
}

and the movieclip will move according to it's speed...

pretty simple and useful eh ;)?

Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to AS: ClipEvents Jul. 26th, 2005 @ 05:36 AM Reply

May as well add the full list from the AS Dictionary:

load The action is initiated as soon as the movie clip is instantiated and appears in the Timeline.

unload The action is initiated in the first frame after the movie clip is removed from the Timeline. The actions associated with the Unload movie clip event are processed before any actions are attached to the affected frame.

enterFrame The action is triggered continually at the frame rate of the movie clip. The actions associated with the enterFrame clip event are processed before any frame actions that are attached to the affected frames.

mouseMove The action is initiated every time the mouse is moved. Use the _xmouse and _ymouse properties to determine the current mouse position.

mouseDown The action is initiated when the left mouse button is pressed.

mouseUp The action is initiated when the left mouse button is released.

keyDown The action is initiated when a key is pressed. Use Key.getCode() to retrieve information about the last key pressed.

keyUp The action is initiated when a key is released. Use the Key.getCode() method to retrieve information about the last key pressed.

data The action is initiated when data is received in a loadVariables() or loadMovie() action. When specified with a loadVariables() action, the data event occurs only once, when the last variable is loaded. When specified with a loadMovie() action, the data event occurs repeatedly, as each section of data is retrieved.

Also, you can add the code for event handlers on the main timeline if you wish, rather than on the MC. Say you have an MC with the Instance Name 'PIE' - rather than having this code on the clip:

onClipEvent (enterFrame){
//do stuff;
}

You can add this to your main timeline, first frame, instead:

PIE.onEnterFrame= function(){
//do stuff;
}


- - Flash - Music - Images - -

BBS Signature
deltatsunami
deltatsunami
  • Member since: Dec. 31, 2005
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to AS: ClipEvents Dec. 7th, 2006 @ 12:30 AM Reply

awesome denvish!

H3
H3
  • Member since: Dec. 18, 2000
  • Offline.
Forum Stats
Member
Level 21
Blank Slate
Response to AS: ClipEvents Dec. 7th, 2006 @ 10:19 AM Reply

Great post~

Would you argue for or against that it is better to have all AS code in one frame on the timeline than to have onClipEvent on MCs.

I think having code everywhere makes it hard

Paranoia
Paranoia
  • Member since: Apr. 22, 2005
  • Offline.
Forum Stats
Member
Level 35
Game Developer
Response to AS: ClipEvents Dec. 7th, 2006 @ 10:58 AM Reply

At 12/7/06 12:30 AM, deltatsunami wrote: awesome denvish!

This adds nothing >.<


BBS Signature
nacritico
nacritico
  • Member since: Oct. 3, 2005
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to AS: ClipEvents Dec. 19th, 2006 @ 08:31 AM Reply

sorry for reviving this post..
I got a question: "is there anyway to tell the CE i want to make something in the main timeline; for example:
"If(_currentFrame == 2){ "THE MOVIE".gotoAndStop(500)}; what can I write in "THE MOVIE"?

GeoKureli
GeoKureli
  • Member since: Apr. 1, 2003
  • Offline.
Forum Stats
Supporter
Level 19
Game Developer
Response to AS: ClipEvents Dec. 19th, 2006 @ 09:43 AM Reply

At 12/19/06 08:31 AM, nacritico wrote: sorry for reviving this post..
I got a question: "is there anyway to tell the CE i want to make something in the main timeline; for example:
"If(_currentFrame == 2){ "THE MOVIE".gotoAndStop(500)}; what can I write in "THE MOVIE"?

If(_currentframe == 2){
_root.gotoAndStop(500);
}
(lowercase f)

if your asking how to put a clipEvent in the main timeline then use
onEnterFrame = function(){
//code here
}

jamessnake
jamessnake
  • Member since: Dec. 24, 2005
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to AS: ClipEvents May. 12th, 2007 @ 07:14 AM Reply

and if i want to happen it once, lets say, when a variable touches 0 and i want it to add 100 gold or something, once. how do i do that???

neon-dude
neon-dude
  • Member since: Mar. 15, 2006
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to AS: ClipEvents Apr. 18th, 2008 @ 11:46 AM Reply

At 5/12/07 07:14 AM, jamessnake wrote: and if i want to happen it once, lets say, when a variable touches 0 and i want it to add 100 gold or something, once. how do i do that???

You'd do this:

onClipEvent(enterFrame){
if(gold == 0){
gold += 100;
}
}

"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
GustTheASGuy
GustTheASGuy
  • Member since: Nov. 2, 2005
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to AS: ClipEvents Apr. 18th, 2008 @ 12:20 PM Reply

Lolz Inglor's on MSN.


BBS Signature
UnknownFury
UnknownFury
  • Member since: Aug. 10, 2005
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to AS: ClipEvents Apr. 18th, 2008 @ 12:26 PM Reply

At 4/18/08 12:20 PM, GustTheASGuy wrote: Lolz Inglor's on MSN.

Thats weird.. I just said that to sweetskater.

Argentin
Argentin
  • Member since: Aug. 1, 2007
  • Offline.
Forum Stats
Member
Level 15
Game Developer
Response to AS: ClipEvents Aug. 22nd, 2008 @ 01:40 PM Reply

Thank you God
And thenk you for making this thread
it saved me from a Hell Day
I'm just learning AS and I tried 1 whole day to solve a freaking little problem and now i got it thanks to this
thanks a lot

zrb
zrb
  • Member since: Aug. 8, 2006
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to AS: ClipEvents Aug. 22nd, 2008 @ 01:55 PM Reply

You just bumped a 3 year old topic to make a useless post.


School Sux ! || As :Main || As3: Main || Animation: Main || Flash Tutorials ||

BBS Signature
CyberXR
CyberXR
  • Member since: Aug. 22, 2008
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to AS: ClipEvents Sep. 21st, 2008 @ 11:09 AM Reply

Easy to read and good to know knowleadge. Sorry to say that I did already know all this (but that should not be counted in the rating ofc) =)


Check out the coolest Donkey Kong Game on NG!
http://www.newgrounds.com/portal/vi ew/459064
100 posts @ Posted at: 9/15/08 07:36 AM http://www.newgrounds.com/bbs/topic /969232

zuperxtreme
zuperxtreme
  • Member since: Jan. 2, 2005
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to AS: ClipEvents Sep. 21st, 2008 @ 12:00 PM Reply

At 8/22/08 01:55 PM, zrb wrote: You just bumped a 3 year old topic to make a useless post.

Saying thanks is not useless.


BBS Signature
No-Brainer
No-Brainer
  • Member since: May. 26, 2007
  • Offline.
Forum Stats
Member
Level 08
Animator
Response to AS: ClipEvents Oct. 16th, 2008 @ 05:59 PM Reply

BUMP. say i can't get my buttons from going to being locked to unlocked. someone wanna help me?


Aimless Adventures - Go start your adventure today! HOME OF REALMS, THE AMAZING NEW WEBCOMIC.

BBS Signature
HomerSexual
HomerSexual
  • Member since: May. 26, 2007
  • Offline.
Forum Stats
Member
Level 22
Programmer
Response to AS: ClipEvents Jan. 10th, 2009 @ 11:09 PM Reply

You cant nest onClipEvent(load){
with
onClipEvent(enterFrame){

just to let ya know.