00:00
00:00

AS: ClipEvents

6,087 Views | 15 Replies
New Topic Respond to this Topic

AS: ClipEvents 2005-07-26 05:27:52


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

Response to AS: ClipEvents 2005-07-26 05:36:48


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

Response to AS: ClipEvents 2006-12-07 00:30:25


awesome denvish!

Response to AS: ClipEvents 2006-12-07 10:19:20


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

Response to AS: ClipEvents 2006-12-07 10:58:00


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

This adds nothing >.<


BBS Signature

Response to AS: ClipEvents 2006-12-19 08:31:59


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"?

Response to AS: ClipEvents 2006-12-19 09:43:34


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
}


This blog I made | This game sucks | I, twit

Just trying to get enough Twitter followers to quit Facebook forever

Response to AS: ClipEvents 2007-05-12 07:14:35


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

Response to AS: ClipEvents 2008-04-18 11:46:38


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

Response to AS: ClipEvents 2008-04-18 12:20:12


Lolz Inglor's on MSN.


BBS Signature

Response to AS: ClipEvents 2008-04-18 12:26:39


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

Thats weird.. I just said that to sweetskater.

Response to AS: ClipEvents 2008-08-22 13:40:43


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

Response to AS: ClipEvents 2008-09-21 11:09:40


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

Response to AS: ClipEvents 2008-09-21 12:00:59


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

Response to AS: ClipEvents 2008-10-16 17:59:34


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

Response to AS: ClipEvents 2009-01-10 23:09:11


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

just to let ya know.