Basics of Flash Actionscript

 

Before becoming an Actionscript warrior, like any other tool, one should have clear understanding of the basics. One of the most important concept, often ignored, is Events.

 

So what are events?  It is as same as we all know in common English language. But for better understanding of this term in Actionscript, let us see an example in our day to day life. Generally

we follow,  hopefully all, one etiquette before entering a house, is ringing the bell. Actually we directly don’t ring the bell, we just press the switch, which is an event here, which causes the bell to ring, which is an action.

 

So to cause any action do we need an event?  Is a billion dollar question in Actionscript.

 

Simple answer is YES.

 

Let us move on to a wider spectrum of the above concept. Here we are going to see another new concept,  Event Handlers which is just an extension to the above concept.

 

As the name suggests, it is nothing but a system which handles events. Just we will continue with the above example, ringing the bell. To make a bell to ring, we need two objects, one is switch, the other is bell itself. But the bell doesn’t ring on its own. You need to press the switch. Until you press the switch bell waits for that event to happen. Once that event occurs, bell handles that event and produces the sound action. Here the bell is Event Handler.

 

Let us sum up, pressing the switch is Event and the bell which is waiting to handle the event is Event Handler. So for an action to occur, we need an Event and Event Handler to process that event.

 

Let us translate this concept in Actionscript coding.

 

                              switch_btn.onPress = function(){

                                trace(“Bell is Ringing”);

                              }

 

 

Here the switch_btn is Button object on which the user is going to click.

onPress function is Event Handler.

Trace Statement “Bell is Ringing” is action.

 

Just few comments here, pressing the switch_btn is event, onPress function is an Event Handler waiting to capture the event. When you run this code, we can see that once the user clicks on the switch button,  “Bell is Ringing” is displayed in the output panel.

 

Always Remember here, until the user clicks on the button, the code will never be executed,  just as until you press the switch, the bell will never ring.

 

Reference Book:  Flash Action script Bible – Robert Reindhart

Tags: , , , , , , , ,

Leave a Reply