Flash actionscript three version to handle the difference between events

Source: Internet
Author: User

Problem:
I'm going to repeat a piece of code.


Solution:
Adding listeners and association processing methods to the Enterframe event


Discuss:
Handling Enterframe Events in ActionScript 2.0 is simple, and you simply create a timeline function call Onenterframe and then call it automatically every time the new frame starts. There are all kinds of events in ActionScript 3.0 that need to be controlled, and it's not hard to access them.
If you are familiar with the Eventdispatcher class in ActionScript 2.0, you are well versed in the ActionScript 3.0 event handle. To broadcast the Enterframe event, you have to tell your program to listen to the event and then specify the back function. Using the AddEventListener method can be done:


AddEventListener (type:string, listener:function)


The type parameter indicates the kind of event you want to listen for, such as "Enterframe". However, the best way to make mistakes in these strings is to invoke the static member properties of the event class: Import the event class and invoke the AddEventListener method: AddEventListener (Event.enter_frame, onent Erframe);
The second parameter, Onenterframe, points to a callback function defined in the class that needs to be passed into an instance of the EVENT:


Import flash.events.Event;
Private Function Onenterframe (event:event) {}


An Event object contains information about the event. Here's a simple example: draw some random lines.


Package {
Import Flash.display.Sprite;
Import flash.events.Event;


public class Exampleapplication extends Sprite {


Public Function exampleapplication () {
Graphics.linestyle (1, 0, 1);
AddEventListener (Event.enter_frame, onenterframe);
}


Private Function Onenterframe (event:event): void {
Graphics.lineto (Math.random () *, Math.random () * 400);
}
}
}










Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.