Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: MouseEvent.MOUSE_OVER after a MOUSE_DOWN

That's basically what I'd envision.

 

That said, please don't do what I said without confirming it's actually better.  For one thing, "premature optimization is the root of all evil in programming" (said Knuth or something).  For another, I just did some repeat searching to find the main article I based all that on (something about CPU usage in flash apps) and couldn't find it, but I did find several articles stating the exact opposite: that MOUSE_MOVE is "less resource intensive" than ENTER_FRAME.  I don't actually believe those, but it's always possible... check for yourself please, as I have only a little knowledge in this area... a.k.a. a dangerous thing.


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: MouseEvent.MOUSE_OVER after a MOUSE_DOWN

I wrote above that I had read conflicting claims as to whether MOUSE_MOVE or ENTER_FRAME was better.

 

I'm sure it depends on the circumstances, but the code following shows that on the 0.9.3 simulator, on my machine, MOUSE_MOVE events are delivered at approximately 100 Hz (events per second).  The same code run on my host in ADL shows a rate of 125 Hz.  I think that means the individual platform limits the rate to some reasonable but probably undocumented value.  The PlayBook may give more or fewer events per second... we'll have to see.

 

The default ENTER_FRAME rate is 24 Hz, and you can make that slower in some cases.

 

So if you are already using ENTER_FRAME for other purposes, and don't need the high-speed stream of events that MOUSE_MOVE gets you, then definitely you should avoid it.

 

 

package {
    // don't use wildcard imports in real code!
    import flash.display.*;
    import flash.events.*;
    import flash.utils.*;

    import qnx.ui.text.Label;

    [SWF(backgroundColor="#cccccc")]
    public class EventRateTest extends Sprite {
        public function EventRateTest() {
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;

            stage.addEventListener(MouseEvent.MOUSE_DOWN, onEvent);
            stage.addEventListener(MouseEvent.MOUSE_MOVE, onMove);

            label = new Label();
            label.width = 500;
            label.text = "count: ? rate: ?";
            addChild(label);
        }

        private var label:Label;
        private var move_count:int;
        private var start_time:int = getTimer();

        private function onMove(e:MouseEvent):void {
            move_count++;
            var rate:Number = move_count / (getTimer() - start_time) * 1000.0;
            label.text = "count: " + String(move_count) + " rate: " + rate.toFixed(3) + " Hz";
        }

        private function onEvent(e:Event):void {
            move_count = 0;
            start_time = getTimer();
        }
    }
}

(The code basically displays move events per second, resetting the count and time whenever you click.)

 

 


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 168
Registered: ‎01-13-2011
My Device: Not Specified

Re: MouseEvent.MOUSE_OVER after a MOUSE_DOWN

Thanks for the investigation. I guess in my case, the traffics is between processing more mouse move events and having to run a hitTestPoint on 72 colored blocks at each frame. Anyways, for me, my color picker will probably only be opened by the user for like 2 seconds while they pick a color.
Developer
Posts: 168
Registered: ‎01-13-2011
My Device: Not Specified

Re: MouseEvent.MOUSE_OVER after a MOUSE_DOWN

*traffic --> tradeoff
Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: MouseEvent.MOUSE_OVER after a MOUSE_DOWN

I think in a case where I had a huge batch of square objects arranged in an array onscreen, I'd just listen on the parent and take the local coordinates and do the math (divide by size, etc, whatever) to convert them directly to array indices.  

 

Ignoring the possible-but-irrelevant one pixel errors at the borders between them, that would work and be a pretty low-overhead technique.  

 

Maybe not simpler than whatever alternative you've got... obviously you'll pick what works best for you overall.


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Highlighted
Developer
Posts: 168
Registered: ‎01-13-2011
My Device: Not Specified

Re: MouseEvent.MOUSE_OVER after a MOUSE_DOWN

I think you're right. It would be more efficient to listen to their parent.