开发者

Actionscript 3 for Android - should I attach mouse event listeners to the stage or to individual sprites?

开发者 https://www.devze.com 2023-03-28 06:34 出处:网络
In AS3 on Android is it bad from a performance perspective to attach mouse event listeners to individual sprites rather than to the stage?

In AS3 on Android is it bad from a performance perspective to attach mouse event listeners to individual sprites rather than to the stage?

I am writing an app for an And开发者_StackOverflow中文版roid phone using AS3 in Flash Builder. The app has multiple screens that respond to user touch. The screens are arranged in a hierarchy and show list data so that when you click on an item in a list you are presented with a new screen with a new sub list on it.

I have been using an event listener to detect mouse / touch input and based on something I read that indicated that performance is much better if you keep the number of objects you are listening to to a minimum I have attached the mouse listeners from each screen to the stage object.

This all works fine but I am finding that as I move between screens (and they get popped or pushed onto the dislay stack) I have to keep track of alot of adding and removing listeners to the stage object. If I don't then windows higher up the hierarchy than the current screen keep receiving mouse events.

If I used listeners attached to sprites in each window then when the window was removed from the display even though it is kept in memory (ready to be popped back when a child window is closed) it won't receive any mouse events....

Performance doesn't seem to be impacted using listeners directly on sprites when using my HTC phone to test with, however I obviously don't know what it will be like on other phones. Does anyone have any experience either way or a view on the best approach?


I would recommend to use Listeners on specific sprites, as it will be easier to code and maintain, also coordinates conversion might get cumbersome to manage with different screen/sprites sizes, and removing/adding listeners might not be so easy to maintain as you add more screens...

As for performance, I don't believe Listeners will have any impact, it is just a function that get called when the sprite is clicked, if you don't set a Listener, the OS registers the click anyway and sends it down to the lower level View until it eventually finds a Listener to the event, or drops it.

0

精彩评论

暂无评论...
验证码 换一张
取 消