Event Programming Flash
October 2, 2009
Yes, One of the most important part in flash is Event. Flash is an event-driven programming language. Event is very closely related with interaction. Anything happens inside your flash environment either Mouse click, Keyboard press or Load completion is an event while mouse click and others are an interaction that trigger an event.
In order to intercept an Event, First you must register.
Below is Register Listener example :
addEventListener(TypeOfEvent.NameOfEvent,AnyMethod);
and for example if you want flash stage to hear an event then you must add
stage.addEventListener(TypeOfEvent.NameOfEvent,AnyMethod);
TypeOfEvent => Typically this is the class of an Event Class example MouseEvent.
NameOfEvent => Typically this is kind of constant variable of that class Event you used, for example a MouseEvent Class has a variable CLICK as its event type.
AnyMethod => function you would like to execute when an event occured.
If you want flash stage to hear a mouse click event then it will be.
stage.addEventListener(MouseEvent.CLICK,testClick);
function testClick(e:MouseEvent):void{
trace(“It works dude !”);
}
Don’t forgot that “e” from “e:MouseEvent” is an event object. You can also try few things like who trigger me with e.target. Happy Coding and hope you enjoy.
Actionscript Naming Convention.
September 30, 2009
After we have a good fight in AS3. Let’s also talk a little bit about Naming Convention in actionscript. Naming Convention is extremely important in almost every programming language not just actionscript. When your application grow bigger, the tendency to be difficult to manage is also grow. One way that helps your application more readable is with Naming Convention.
So How can it be done ? Let’s take a look.
Class in Actionscript should be marked as CapitalLater at first Character, Example : SexyWoman.
Object is following a Camel Case rule. Like a camel, which have several humps , a name likes Rosalie Bradford should be marked as rosalieBradford.
You can see that Object naming-rule is exactly opposing class named-rule which at first letter should capital.
A variable and properties of naming-convention is like an object naming-convention.
A constant variable should be capital letter. example : BOUNCE_LEFT.
separator between words is underscore.
That’s our note today. Hope you enjoy .
Package in Actionscript 3 (Part II)
September 29, 2009
So this is the next part of our ‘Package Tour’. In this notes, we will look more about package.
Supposed there is a package like this.
package com.myFlashNotes {
public class PackageTest{
public function PackageTest{}
}
}
code above shows that an actionscript file is inside folder com then myFlashNotes (com->myFlashNotes)
the folder Hierarchy :
- com
- myFlashNotes
PackageTest (Actionscript Class).
Note that the bold font is our folder name and the italic font is our actionscript class name.
Package in AS 3
September 28, 2009
Okay, so this is my first post and because it is the first one, let’s notes something short and simple but extremely necessary. Yes, it is package. You will need this when you are going to make a class.
Package mechanism is similar to folder. Package will bundle your class as well as your logic. So how do we play with this package ? Let’s see.
Create your actionscript file and named it whatever you like. For this notes i will use NotePackageTest.as
open it with your text editor.
then you defined the package syntax along with two brackets.
like this:
package {}
after that you can type what inside that package and it will be our actionscript class name.
package {
public class NotePackageTest{
public function NotePackage():void{
super();
}
}
}
and that’s it.
ATTENTION :
This is really very quick explanation about using package and it doesn’t cover all essential stuffs in package. Be sure to watch the next one.