Forum Topic: AS: ClipEvents

(3,964 views • 16 replies)

This topic is 1 page long.

<< < > >>
None

Inglor

Reply To Post Reply & Quote

Posted at: 7/26/05 05:27 AM

Inglor NEUTRAL LEVEL 17

Sign-Up: 01/26/03

Posts: 10,948

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


None

Denvish

Reply To Post Reply & Quote

Posted at: 7/26/05 05:36 AM

Denvish DARK LEVEL 46

Sign-Up: 04/25/03

Posts: 16,236

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

None

deltatsunami

Reply To Post Reply & Quote

Posted at: 12/7/06 12:30 AM

deltatsunami LIGHT LEVEL 11

Sign-Up: 12/31/05

Posts: 706

awesome denvish!


None

H3

Reply To Post Reply & Quote

Posted at: 12/7/06 10:19 AM

H3 NEUTRAL LEVEL 21

Sign-Up: 12/18/00

Posts: 199

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


None

Paranoia

Reply To Post Reply & Quote

Posted at: 12/7/06 10:58 AM

Paranoia DARK LEVEL 34

Sign-Up: 04/22/05

Posts: 9,697

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

This adds nothing >.<

BBS Signature

None

nacritico

Reply To Post Reply & Quote

Posted at: 12/19/06 08:31 AM

nacritico NEUTRAL LEVEL 12

Sign-Up: 10/03/05

Posts: 86

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


None

ImpotentBoy2

Reply To Post Reply & Quote

Posted at: 12/19/06 09:43 AM

ImpotentBoy2 LIGHT LEVEL 18

Sign-Up: 04/01/03

Posts: 5,318

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
}

Some times my "L" key decides not to work.


None

jamessnake

Reply To Post Reply & Quote

Posted at: 5/12/07 07:14 AM

jamessnake EVIL LEVEL 03

Sign-Up: 12/24/05

Posts: 1

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


None

neon-dude

Reply To Post Reply & Quote

Posted at: 4/18/08 11:46 AM

neon-dude LIGHT LEVEL 09

Sign-Up: 03/15/06

Posts: 752

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

None

GustTheASGuy

Reply To Post Reply & Quote

Posted at: 4/18/08 12:20 PM

GustTheASGuy LIGHT LEVEL 08

Sign-Up: 11/02/05

Posts: 11,370

Lolz Inglor's on MSN.

#ngprogramming at irc.freenode.net
haXe | Keel imperative | Spyro! | Thru you


None

UnknownFury

Reply To Post Reply & Quote

Posted at: 4/18/08 12:26 PM

UnknownFury EVIL LEVEL 26

Sign-Up: 08/10/05

Posts: 6,031

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

Thats weird.. I just said that to sweetskater.

Portfolio(Under construction): UnknownFury.com |
Msn: giant_ak_47@msn.com | Contact: me@unknownfury.com
Follow me on twitter!


None

Argentin

Reply To Post Reply & Quote

Posted at: 8/22/08 01:40 PM

Argentin DARK LEVEL 14

Sign-Up: 08/01/07

Posts: 945

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

BBS Signature

None

zrb

Reply To Post Reply & Quote

Posted at: 8/22/08 01:55 PM

zrb LIGHT LEVEL 11

Sign-Up: 08/08/06

Posts: 4,513

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

Winking

CyberXR

Reply To Post Reply & Quote

Posted at: 9/21/08 11:09 AM

CyberXR LIGHT LEVEL 09

Sign-Up: 08/22/08

Posts: 176

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


Expressionless

zuperxtreme

Reply To Post Reply & Quote

Posted at: 9/21/08 12:00 PM

zuperxtreme NEUTRAL LEVEL 08

Sign-Up: 01/02/05

Posts: 1,579

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.


None

toontown1

Reply To Post Reply & Quote

Posted at: 10/16/08 05:59 PM

toontown1 NEUTRAL LEVEL 06

Sign-Up: 05/26/07

Posts: 126

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

fear me and my ass.

BBS Signature

None

uzi47

Reply To Post Reply & Quote

Posted at: 1/10/09 11:09 PM

uzi47 FAB LEVEL 17

Sign-Up: 05/26/07

Posts: 1,786

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

just to let ya know.

BBS Signature

All times are Eastern Standard Time (GMT -5) | Current Time: 01:10 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!