Tutorial
Author's blog: www.kingda.org
ActionScript 3.0 Series Tutorial (1): Have a close contact with Flash9 first!
Flash Professional 9 ActionScript 3.0 Preview version is released today, which means that from now on we can use not only flex and AS3.0, but also use the Flash IDE we have always been familiar with for AS3.0 development.
Unlike Flex 2, Flash 9 alpha (that is, the Flash Professional 9 ActionScript 3.0 Preview above) allows us to create a Fla document based on the timeline for ActionScript 3.0, Rather than a state based Mxml document. In Flash 9 alpha, we can hand-sketch vector maps, create components, add animations, and so on on the stage as before.
My black feather is impatient, first jump open some characteristics of the introduction, straightforward, immediately to an example. While explaining the characteristics of Flash 9 said.
To take care of the novice xdjm, look at the picture and talk. The old bird skipped over to see, lest I wordy. Oh.
Create a new FLA, scribble a square or something, double-click to select Press F8 to convert to MovieClip. Named KINGDA_MC in the properties panel. Exactly the same as before.
A new layer, named actions, is a good habit to keep. Select the first frame, press F9 to open the action panel, and write the following code.
Control+enter, in the Test window, double-click the box, and there will be trace information displayed.
Kingda_mc.doubleclickenabled = true;
Kingda_mc.addeventlistener (Mouseevent.double_click, ClickHandler);
function ClickHandler (event:mouseevent): void {
Trace ("Haha, you double-click me");
}
Direct support double-click the
A little explanation, there are a few different places from AS2.0.
1. In AS2.0, MovieClip is not allowed to add listeners, but in AS3.0, it is OK. talk about the east to the old veteran to listen to, all AS3.0 can be seen by the object, its ancestors are Displayobject class. Standard statements are either indirectly or directly inherited from the Displayobject class. And this displayobject is Eventdispatcher's son. So, we have this corollary:
all the things we see in AS3.0 can send events and listeners. fully applicable to event Model.
It's cool, I'm screwed. AS2.0 in order to solve this problem I also made up an agent to send event class Eventsender. Saved a lot of things, and now even this is not necessary, huo haha.
2.as3.0 to let MovieClip in accept click event, rollover event can be like a button, mouse put up to show hand type, then must add a sentence:
Kingda_mc.buttonmode = true;
A trifle, a stroke.
The event model in 3.as3.0 is very different from the AS2.0.
In short, it is the "norm". You no longer use strings directly to define event names. Again, the new const variable is used to define the event string name, which cannot be changed once defined.
Such as:
public static Const Move:string = ' move ';
Greatly avoids us because the hand mistake, the wrong string, but spends an afternoon to look for the bug. Using this pattern, the compiler immediately discovers and tells us when we make a mistake. how nice.
Give a list of mouse events, you can replace the above source of the event type, you try to play.
For example, you can change to Mouseevent.mouse_over to become the previous onrollover effect.
click:string = "click"
[Static] Dispatched when a user presses and releases the main button of the "user" pointing device over the same interactiveobject. MouseEvent
double_click:string = "DoubleClick"
[Static] Dispatched when a user presses and releases the main button of a pointing device twice in rapid on the succession I Nteractiveobject when this object ' s doubleclickenabled flag is set to true. MouseEvent
mouse_down:string = "MouseDown"
[Static] Dispatched when a user presses the pointing device button over an interactiveobject in the Flash Player window. MouseEvent
mouse_leave:string = "MouseLeave"
[Static] Dispatched by the Stage object, the mouse pointer moves out of the Flash Player window area. Event
mouse_move:string = "MouseMove"
[Static] Dispatched when a user moves the pointing device while it was over a interactiveobject. MouseEvent
mouse_out:string = "Mouseout"
[Static] Dispatched when the user moves a pointing device away from the Interactiveobject instance. MouseEvent
mouse_over:string = "MouseOver"
[Static] Dispatched when the user moves a pointing device over a interactiveobject instance in the Flash Player window. MouseEvent
mouse_up:string = "MouseUp"
[Static] Dispatched when a user releases the pointing device button over an interactiveobject in the Flash Player window. MouseEvent
mouse_wheel:string = "MouseWheel"
Support the mouse wheel, rattling.
To point out, in the example I gave, I used a double click on this event. This is a little special, before you use the double-click event, add a sentence:
Kingda_mc.doubleclickenabled = true;
Because MovieClip is false for the double-click Event, closed.
4. The listener is different.
In AS2.0 we usually create a new object to do the listener. You can also use function as a listener in my example. Unfortunately, because of the AS2.0 design flaws, this point in function is often troubling us. So there is the delegate class to solve.
Today, the AS3.0 uses an excellent traits object architecture (well, this is temporarily unexplained) so that it remembers the point of this. So, brothers, be assured to use function as a listener.
Today is written so much, mainly flash 9 out, my old man excited a bit, all of a sudden wrote so many dongdong. Hope for everyone to help, I hope everyone crazy top support, otherwise no power, this series of tutorials will become eunuch stickers! Hey, Huo ha! ^_^ Quick Reply Support!
This article mainly deals with the event Model section in AS3.0, which is very important. There will be more in-depth tutorials to be covered in more detail. The purpose of this article is to get everyone to use Flash 9 and AS3, to eliminate the sense of strangeness. Write a shallow, but also please forgive.
The next article introduces very practical Dongdong, class and MovieClip bindings, and one of the major features of Flash 9: Document class. Used to replace the writing code in the timeline of the good stuff.