Quantunet.com

My Account

Joins Us
Flash 8 Actionscript 2.0 QuickSkills
updateAfterEvent()  

Stage Rendering Independent of frame rate!
     
Mouse.hide();
myMouseCursor.onMouseMove=function()
{
    this._x=_root._xmouse;
    this._y=_root._ymouse;
}
  Mouse.hide();
myMouseCursor.onMouseMove=function()
{
    this._x=_root._xmouse;
    this._y=_root._ymouse;
updateAfterEvent();
}
     
The function is called every time the mouse is moved and the new position of the cursor reset. However the screen is only refreshed every time flash enters a new frame (by default).This means if the position changes quickly screen takes a lag time to catch up as flash re-renders the stage and displays the object in its new position.   By adding the updateAfterEvent() function we can force flash to re-render the stage each time the code is run.as the code is triggered to by the mouse movement. the faster the mouse moves the more frequently the stage is re-rendered. Giving us a dynamic and proportional control over the amount of re-rendering
The problem is that udateAfterEvent() only works with certain clip events (mouseMove, mouseDown, MouseUp, keyDown, keyUp.) to call it for as part of ANY function we must use the setInterval() function. The setInterval() function simply sets the time interval between successive calls of a function. in this case calling the function every 250 milliseconds. interval = 250 set interval (this, "updateAfterEvent", interval) The code here forces the flash player to render the movieclip on the stage (main time line) every 250 milliseconds calling the updateAfterEvent() function directly. OR you can put updateAfterEvent inside another function and call that function using the setInterval() function. for example


function randomNumber() {
field.text = Math.round(Math.random() * 1000);
updateAfterEvent();
}var animate = setInterval(randomNumber, 150);

updateAfterEvent is inside the our function "randomNumber()" .The setInterval function is then set to activate the random number generator and updatreafterEvent every 150  milliseconds. More Examples 2d actionscript animation

© 2008 Quantunet LLC All Rights Reserved | Intellectual Property | Terms of Use | Privacy
Home | About Quantunet | FAQ's | Contact Us