The role of AS3 Updateafterevent

Source: Internet
Author: User
Tags setinterval
There are three classes in Flash that have this attribute, and these three classes are: Keyboardevent,mouseevent,timerevent. The event that invokes the Updateafterevent property forces the rendering operation to be performed immediately, rather than waiting for the rendering phase. However, if updateafterevent frequently causes performance problems, you should avoid using it.


1.updateAfterEvent How to use?
A lot of people do mouse follow effect, always found that the mouse movement is not smooth, do not know how to solve.
In fact, the method is very simple, you just need to add a sentence updateafterevent () ok.

2. Let's take a look at how help explains As3 's updateafterevent:
When the Updateafterevent function is called within the onclipevent () handler or as part of a function or method passed to SetInterval (), the display is updated (regardless of the number of frames per second set for the movie). If the call to Updateafterevent is not within the onclipevent () handler and is not part of a function or method passed to SetInterval (), Flash ignores the call. This function only works on certain Mouse and MovieClip processing functions: MouseDown, MouseUp, MouseMove, KeyDown, and keyUp handlers for Mouse classes; MovieClip, OnMouseMove Usedown, OnMouseUp, OnKeyDown, and onKeyUp processing functions. It does not work on the Key class.

3. In fact, the updateafterevent function is to make the cursor movement appear smoother.
The following is an example of updateafterevent to make it easier for everyone to understand its role.
When the mouse moves to the "updateafterevent" area on the left of the stage, the mouse movement will be smooth, and when the mouse moves to the right of the stage "no execution updateafterevent" area, the mouse movement will be intermittent, not fluent game http:// Www.shengshiyouxi.com.
Look at as:
Use Updateafterevent () to continue to refresh the stage so that the cursor movement looks smooth.




Package
{
Import Flash.display.Bitmap;
Import Flash.display.Sprite;
Import flash.display.StageAlign;
Import Flash.display.StageScaleMode;
Import flash.events.MouseEvent;

public class Tupdateevent extends Sprite
{
[Embed (source= "assets/tt2.jpg")]
private Var Img:class;

private Var Bmp:bitmap;
Public Function tupdateevent ()
{
Stage.align = Stagealign.top_left;
Stage.scalemode = Stagescalemode.no_scale;


BMP = new img () as Bitmap;
AddChild (BMP);

Stage.addeventlistener (Mouseevent.mouse_move, Stagemousemove);
}

Private Function Stagemousemove (evt:mouseevent): void
{
bmp.x = This.mousex;
BMP.Y = This.mousey;

Evt.updateafterevent ();
}
}
}



As can be seen from the above example, call Updateafterevent () function and do not call the function visual effect is not the same, the call will feel very smooth, do not call will have a flicker of the feeling

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.