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