How to keep an object moves together with scrollbar drag

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
alex298
Posts: 101
Joined: Mon May 01, 2006 1:17 pm

How to keep an object moves together with scrollbar drag

Post by alex298 » Fri May 09, 2008 11:22 am

Hi,

I don't know how to keep an object moving hand in hand with a scrollbar. Here's my problem:

1. I layout a group "MyImage" with a vertical scrollbar in a card. There is a picture loaded in the group "MyImage".

2. A field "test" is layout in some position inside the group "MyImage".

I wish that the field "test" will always keep in the same position relative to the picture inside the group "MyImage" when the vertical scrollbar drag up and down.

I tried to use the following code:
on scrollbarDrag
## Get the co-ordination of group "MyImage"
put the left of group "MyImage" into x1
put the top of group "MyImage" into y1

## Update the new position
set the loc of field "test" to item 1 of the loc of field "test", item 2 of the loc of field "test" + the vscroll of group "MyImage"
end scrollbarDrag
Obviously the above codes do not works. The the vscroll of group "MyImage" keeps updating the "total amount" while the vertical scrollbar is dragging.

Could you please provide some idea how to do it?

Thanks and best regards
Alex
Nice to meet all of you.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Fri May 09, 2008 1:53 pm

Hi Alex,

You don't need any script to do this. Just group the field and the image together and they will scroll together.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

alex298
Posts: 101
Joined: Mon May 01, 2006 1:17 pm

Post by alex298 » Fri May 09, 2008 2:40 pm

Hi Mark,

Thanks for your kind assistance. Actually I think to group the group "MyImage" and field "test" before.

Since many pictures will be showing one by one in the group "MyImage", therefore the field "test" will also be used with other pictures. If I group the field "test" with the group "MyImage", I have to group, ungroup and group for a picture, then group, ungroup and group for other pictures......

Moreover I have more than one objects to display on the group "MyImage", the grouping method will be quite tedious. That's why I am thinking to use scripts to do that.

Thanks and best regards
Alex
Nice to meet all of you.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Fri May 09, 2008 2:47 pm

Alex,

That sounds way too complex. I don't know exactly what you are trying to do, but usually there are two ways.

Use one group, with an image and a field, and change the text of the image or the filename as necessary.

Or create one group with an image and a field, and clone it before setting the text of the image or its filename. Delete the group when you don't need it anymore.

Usually, it isn't necessary to create a new group for each image you want to display.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Post Reply