AS3 Optimization Tip from Big Spaceship
[ 2008-12-17 22:12:31 | Author: liuhuan ]
From Big Spaceship: http://labs.bigspaceship.com/2008/10/16/as3-optimization-tip/
Creating a site that has a lot of transitions is fun. One that uses a ParallaxManager to manage and scroll 6 layers of objects is also fun.
What isn’t fun is having the user leave the site to check mail, work, oh, I don’t know, do something else and have the site continually scroll. In steps ‘Event.MOUSE_LEAVE’.
The only drawback is that one cannot effectively test this in the IDE. It does, however, work in the browser.
This might also be expanded to do a little house cleaning while the user isn’t using the site. Once you have access to ’stage’, add the listener. Then use the functions to stop and start the site. I’ve left out the project specific code and what you see here is bare bones. MOUSE_MOVE only happens when the user is actually on the stage so that is how we re-activate things. Thanks go out to Kirupa.
Creating a site that has a lot of transitions is fun. One that uses a ParallaxManager to manage and scroll 6 layers of objects is also fun.
What isn’t fun is having the user leave the site to check mail, work, oh, I don’t know, do something else and have the site continually scroll. In steps ‘Event.MOUSE_LEAVE’.
The only drawback is that one cannot effectively test this in the IDE. It does, however, work in the browser.
This might also be expanded to do a little house cleaning while the user isn’t using the site. Once you have access to ’stage’, add the listener. Then use the functions to stop and start the site. I’ve left out the project specific code and what you see here is bare bones. MOUSE_MOVE only happens when the user is actually on the stage so that is how we re-activate things. Thanks go out to Kirupa.
Quote
stage.addEventListener(Event.MOUSE_LEAVE, _onLeaveStage, false, 0, true);
// followed by:
private function _onLeaveStage($evt:Event):void
{
// disable site code
stage.addEventListener(MouseEvent.MOUSE_MOVE, _onReturnToStage, false, 0, true);
};
private function _onReturnToStage($evt:MouseEvent):void
{
stage.removeEventListener(MouseEvent.MOUSE_MOVE, _onReturnToStage);
//re-enable site code
};
// followed by:
private function _onLeaveStage($evt:Event):void
{
// disable site code
stage.addEventListener(MouseEvent.MOUSE_MOVE, _onReturnToStage, false, 0, true);
};
private function _onReturnToStage($evt:MouseEvent):void
{
stage.removeEventListener(MouseEvent.MOUSE_MOVE, _onReturnToStage);
//re-enable site code
};
Comments Feed: http://www.liuhuan.com/blog/feed.asp?q=comment&id=923
There is no comment on this article.
You can't post comment on this article.