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

Native Development

Reply
Regular Contributor
CrozyBB
Posts: 83
Registered: ‎07-19-2012
My Device: Bold 9790, Dev Alpha A
Accepted Solution

Drag and Repositioning of a Control

I've been trying to figure out a way to drag controls (i.e. imageView) around a page and this is what I've come up with so far

            onTouch: {
                var iniX = 0;
                var iniY = 0;
                
                if (event.isDown()) {
                    iniX = event.windowX;
                    iniY = event.windowY;   
                } else if (event.isMove()) {
                    myImage.translationX = event.windowX - iniX;
                    myImage.translationY = event.windowY - iniY; 
                }
            }

 

However this doesn't seem to work. I think there might be a type mismatch for the myImage.Translation property but I haven't been able to figure that out. Any thoughts? Or perhaps there is a better way of dragging items?

Please use plain text.
Developer
soaman
Posts: 848
Registered: ‎03-03-2011
My Device: Z10

Re: Drag and Repositioning of a Control

Every the move event is generated, you are reseting iniX and iniY!

Create properties iniX and iniY, and reset them inside 'if (event.isDown())'.
--------------------------------------------------------------------------------------
Leader of Ljubljana BlackBerry Developer Group
BlackBerry Certified Builder for Native Application Development
Please use plain text.
Regular Contributor
CrozyBB
Posts: 83
Registered: ‎07-19-2012
My Device: Bold 9790, Dev Alpha A

Re: Drag and Repositioning of a Control

Thank you that worked :smileyhappy:

Please use plain text.