Copying groups into a 'master' group to create a mobile scro

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
MrCrussell
Posts: 23
Joined: Wed Nov 05, 2014 11:30 am

Copying groups into a 'master' group to create a mobile scro

Post by MrCrussell » Fri Dec 12, 2014 2:08 pm

Hi,
I'm trying (without much success) to dynamically create a series of graphical buttons which need to be added to a group which can then be scrolled using the mobileControlCreate command so I end up with a graphical menu for an iOS app I'm writing.

The problem is, looking at the API documentation, I don't seem to be able to copy a group to a group - is it possible to do this, or am I just looking at the problem in the wrong way?

Explanation
--------------
I have a group, stored on a separate card which comprises of a background image (an arrow) over that is placed an image, a title and subtitle, a cost and a 'play' button
I want to create a scroller on my device which will contain multiple copies of the group described above which will act as menu items, allowing the user to select an option and see relevant details on another card.

I used the code mentioned in one of the tutorials to (hopefully) create the native scroller but it doesn't seem to work (I think because I'm trying to copy a group into another group).

Thx

Crussell

The code I have so far is:

Code: Select all

global aryVideoList
global gVidModule

local scrollContainer
local sScrollerID

on preOpenCard
   local tScrollerRect, tContentRect
   if environment() is not "mobile" then
      answer( "Only works on a mobile platform" )
   else
      lock screen
      // Set up the 'master scroll container'
      create group "scrollContainer"
      set the width of it to 600
      set the height of it to 800
      set the location of it to (400, 800)
 
      // Set up the group which holds the list of menu items     
      create group "grpOptions"
      put 320 into xLoc
      put 230 into yLoc 
     // Repeat 3 times to give enough content to exceed the master container
      repeat 3 times
         repeat for each key thisKey in aryVideoList
            put aryVideoList[thisKey] into thisVideo
            copy group "grpArrow" of card "objects" to group "grpOptions" of this card
            set the name of it to thisVideo['sku']
            put thisVideo['title'] into field "lblTitle" of it
            put thisVideo['numvids'] & " videos" into field lblNumvids of it
            if thisVideo['owned'] = "yes" then
               put "View" into field "lblAction" of it
            else
               put "£" & thisVideo['price'] into field "lblAction" of it
            end if
            set the location of it to ( xLoc, yLoc )
            put yLoc + 160 into yLoc
         end repeat
      end repeat
      -- Copy the complete list of menu items into the master container 
      copy group "grpOptions" to group "scrollContainer"
      set the visible of group  "grpOptions" to true
      put the left of group "grpOptions", the top of group "grpOptions", the formattedHeight of group "grpOptions"  into tContentRect 

      mobileControlCreate "scroller", "menuScroll"
      put the result into sScrollerID
      mobileControlSet "menuScroll", "rect", tScrollerRect
      mobileControlSet "menuScroll", "contentRect", tContentRect
      mobileControlSet "menuScroll", "visible", true
      mobileControlSet "menuScroll", "scrollingEnabled", true
      mobileControlSet "menuScroll", "vindicator", true
      mobileControlSet "menuScroll", "vscroll", 0

   end if
end preOpenCard

on scrollerDidScroll hOffset, vOffset
   //When user scrolls, scroll the group
   set the vScroll of group "scrollContainer" to vOffset
end scrollerDidScroll

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Copying groups into a 'master' group to create a mobile

Post by Klaus » Fri Dec 12, 2014 2:23 pm

Hi MrCrussel,

not sure what the problem might be, but here some general hints:
1. Do not use IT more than neccessary, IT will change ITs content when you least exspect IT :D
ALWAYS store IT into another variable before using it more than once!
...
create group "scrollContainer"
put IT into tScrollContainer
set the width of tScrollContainer to 600
...

2. KEYS of an array should be in DOUBLE QUOTES ->
...
## put thisVideo['title'] into field "lblTitle" of it
put thisVideo["title"] into field "lblTitle" of it
...

3. You need to supply 4 (FOUR) integers for the "contentrect" (every RECT actually) of a native scroller, but your script only provides THREE values:
...
put the left of group "grpOptions", the top of group "grpOptions", the formattedHeight of group "grpOptions" into tContentRect
## 1. left
## 2. top
## 3. formattedheight
## 4. ? Missing!
...

4. COPYING an object will NOT fill the variable IT with the ID of the copied object!
So you need to address the group in another way:
...
copy group "grpArrow" of card "objects" to group "grpOptions" of this card
## DON'T WORK:
## set the name of IT to thisVideo["sku"]

## Correct address:
set the name of grp "grpArrow" of group "grpOptions" of card "objects" to thisVideo["sku"]
...
See also 1.


Best

Klaus

MrCrussell
Posts: 23
Joined: Wed Nov 05, 2014 11:30 am

Re: Copying groups into a 'master' group to create a mobile

Post by MrCrussell » Fri Dec 12, 2014 3:04 pm

Thanks Klaus, as a newbie to Livecode I'm still getting to grips with the way to reference stuff :)

I'll give your suggestions a try and see what happens.

many thanks!

Chris

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Copying groups into a 'master' group to create a mobile

Post by Klaus » Fri Dec 12, 2014 3:16 pm

Hi Chris,

you're welcome! :D

Please also check these great learning reasources:
http://www.hyperactivesw.com/revscriptc ... ences.html


Best

Klaus

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Copying groups into a 'master' group to create a mobile

Post by Dixie » Fri Dec 12, 2014 3:20 pm

Hi...

I have attached a stack that should show you what you want to do... It uses one group and duplicates it as many times as needed, it's basic, it doesn't look very good in that it has not been 'skinned', but it works...:-)
Attachments
scrollButtons 2.livecode.zip
(2.72 KiB) Downloaded 215 times

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Copying groups into a 'master' group to create a mobile

Post by Klaus » Fri Dec 12, 2014 4:48 pm

Sorry, little mistake!
This:
...
## Correct address:
set the name of grp "grpArrow" of group "grpOptions" of card "objects" to thisVideo["sku"]
...
Should read:
...
## Correct address:
set the name of grp "grpArrow" of group "grpOptions" to thisVideo["sku"]
...

Post Reply