Page 1 of 2

Scroller not working after leaving card

Posted: Thu May 17, 2012 5:47 pm
by Djfuzion
Hey everyone,

I have been having this problem for days now on something I really need to complete and I was too lazy to post on the forums but I just cannot get it to work properly.

I have a card that uses a sqlite db to populate a list that is grouped in a scrolling box (followed the example files on the forums and website) but whenever I go to another card and come back the scrolling doesn't work anymore. I don't even have to touch the scrolling text the first visit for it not to work when I come back.

I have the
on closeCard
if environment() is not "mobile" then exit closeCard
iphoneControlDelete scrollid
end closeCard

just like the examples and tried every variation to "delete" this control so when it enters this card again it is reinitialized and it never works. Any suggestions or this happen to anyone else? I can post more code but I feel like one of you guys would just recognize what is missing from reading this. Thanks everyone!

Nick

Re: Scroller not working after leaving card

Posted: Thu May 17, 2012 5:57 pm
by Klaus
Hi Nick,

1. welcome to the forum :-)

2. How did you create the "scroller"?
Need to take look at that handler or better post your complete card script.


Best

Klaus

Re: Scroller not working after leaving card

Posted: Thu May 17, 2012 7:59 pm
by Djfuzion
Thanks for the welcome :D

Heres most of it minus the silly database functions that don't effect anything. Some things in this might seem weird but its because I have been commenting out and changing things a lot trying to see if any of the changes will change the outcome. The group for the scroller is named scrollGroup in the inspector.


local scrollid

on preOpenCard
# mobGUIStart ---> Inserted by mobGUI plugin
//if "MobGUILib-1335977918014.50293" is not among the lines of the stacksInUse then start using stack "MobGUILib-1335977918014.50293"
//mobGUIPreOpenCard me
# mobGUIEnd
//if environment() is not "mobile" then exit preOpenCard

databaseConnect
put databaseGetContactDetails() into field "List"

put the rect of fld "List" into fldRect
put the formattedHeight of fld "List" into fldHeight
//put "Something" into field "Recipe Category Field"
put the width of fld "List" into fldWidth

set the height of fld "List" to fldHeight
set the unboundedVScroll of group "scrollGroup" to true

iphoneControlCreate "scroller"
put the result into scrollid

iphoneControlSet scrollid, "rect", fldRect
iphoneControlSet scrollid, "contentRect", (0, 0, fldWidth, fldHeight)
iphoneControlSet scrollid, "visible", "true"
iphoneControlSet scrollid, "canBounce", "true"
iphoneControlSet scrollid, "declerationRate", "fast"
iphoneControlSet scrollid, "scrollingEnabled", "true"
iphoneControlSet scrollid, "canScrollToTop", "true"
iphoneControlSet scrollid, "canCancelTouches", "false"
iphoneControlSet scrollid, "delayTouches", "true"
iphoneControlSet scrollid, "vIndicator", "true"
iphoneControlSet scrollid, "indicatorStyle", "black"
iphoneControlSet scrollid, "indicatorInsets", "0,0,0,0"
iphoneControlSet scrollid, "hscroll", 0
iphoneControlSet scrollid, "vscroll", 0

repeat with count = 1 to the number of lines of fld "List"
set the textShift of line count of fld "List" to - 10
end repeat

put the vScroll of group "scrollGroup" into fld 12

databaseConnect
//databaseCreateTable
//databaseInsertRecipesDetails
put databaseGetContactDetails() into field "List"
visual effect push left
end preOpenCard


on closeCard
if environment() is not "mobile" then exit closeCard
iphoneControlDelete scrollid
end closeCard

on scrollerBeginDrag
set the hilitedLine of fld "List" to empty
put empty into fld 12
end scrollerBeginDrag

on scrollerScrollToTop
iphoneControlSet scrollId, "vscroll", 0
end scrollerScrollToTop

on scrollerDidScroll hOffset, vOffset
set the vScroll of group "scrollGroup" to vOffset
put vOffset into fld 12
end scrollerDidScroll

Re: Scroller not working after leaving card

Posted: Thu May 17, 2012 9:04 pm
by Klaus
hi Nick,

I think you need to declare "scrollid" as a LOCAL variable, so the "closecard" handler will know WHAT to delete:
Try this:

Code: Select all

local scrollid

on preOpenCard
  # mobGUIStart ---> Inserted by mobGUI plugin
  ## ...
  iphoneControlCreate "scroller"
  put the result into scrollid
  ##...
end preopencard

on closeCard
  if environment() is not "mobile" then 
    exit closeCard
  end if
  iphoneControlDelete scrollid
end closeCard
Best

Klaus

Re: Scroller not working after leaving card

Posted: Thu May 17, 2012 9:56 pm
by Djfuzion
Thanks for the reply Klaus and I had to double check the code above, I think you might have overlooked it but I do declare that scrollid local variable right at the top of the script.

Re: Scroller not working after leaving card

Posted: Thu May 17, 2012 10:15 pm
by Klaus
Hi Nick,

oops, sorry, yes, sure :oops:

No idea, looks OK so far.
You have this twice in your "preopencard" script:
...
databaseConnect
put databaseGetContactDetails() into field "List"
...
And a rather meaningless "visual effect push left" at the end.
Not that would cause your problem, but who knows :)


Best

Klaus

Re: Scroller not working after leaving card

Posted: Fri May 18, 2012 6:13 am
by FireWorx
Why don't you try taking the scroller build script out of the preopencard script and put it into the on open card script' Also add

on opencard
if the environment is "mobile" then
if "scrollerId" is among the lines of iphoneControls() then
iPhoneControlDelete "scrollerId"
end if
----
Then your scroller build script her
----
end if
closecard

That way every time your card opens if the scroller is already open it will close it. It seems to work for me.
Dave

Re: Scroller not working after leaving card

Posted: Fri May 18, 2012 9:41 am
by Klaus
Looks like I really should save some money and get at least an iPod touch and an iOS license :D

Don't have a cellphone, and really don't need one... 8)

Re: Scroller not working after leaving card

Posted: Fri May 18, 2012 3:46 pm
by Djfuzion
FIreworx, thanks for the suggestion this is just getting so frustrating! I tried all of what you said and still coming back to that card the scroller is stuck. I'm testing this on the simulator, does that make any difference? Also around scrollerid you have it "scrollerid" but sometimes I see that same variable being used in other scripts just scrollerid without the "", does this make any difference between the "" and not using any for these local variables?

This really sucks because I switched over to this from Xcode because some of the more complicated things were getting frustrating but now I come over to live code and the simplest thing in Xcode that I was able to do doesn't work at all for me in this...Just never ends man!

Re: Scroller not working after leaving card

Posted: Fri May 18, 2012 4:15 pm
by rrBUSS9EE
Try setting the size of your field just before building your scroller.

Code: Select all

set the height of fld "list" to the formattedheight of fld "list"

Re: Scroller not working after leaving card

Posted: Fri May 18, 2012 9:19 pm
by Djfuzion
Thanks for the suggestion but unfortunately that did not work either.

I have a Scroller demo downloaded with 2 cards, it loads all of the same exact code I use but its on the preopenstack and that works just fine when going from a different card back to the scroller. In that same demo, i add it to preopencard or open card and the same exact code does NOT work for leaving the card and coming back.......So I tried adding the same code to my preopenstack script but my scroller isn't on the first card that comes up so setting those fields from the other card are odd (I tried set field 1 of card "whatever" where it set any fields in the script to something and that didn't seem to work) and didn't work for me.

Does anyone have an example stack that has the code of setting a scroller on a card NOT in the preopenstack script that can go from one card to the other and back with the scroller still working? I don't understand what is going on..

Re: Scroller not working after leaving card

Posted: Sat May 19, 2012 5:46 pm
by jacque
I have one that works. It's set up in a preOpenCard handler and deleted on closeCard. Where did you put the preOpenCard handler that sets up the control? It should be in the card script, not the stack script.

Another thing that may be happening is that there is an error somewhere else in the scripts, and the setup never happens because the error has aborted all script execution. That wouldn't be as likely if you are testing with the RR demo stack.

If you can post a stripped-down plain demo stack that fails, we can take a look.

Re: Scroller not working after leaving card

Posted: Tue May 22, 2012 3:52 pm
by Djfuzion
WTF, Livecode forums says I hit my attachment quota so I cannot post the actual file...even though I haven't done any attachments whatsoever?

Well I took one of the example code Scroller stacks that has two cards, made it display the same stuff from the first card but on the second card added the script to the card for PreOpenCard and lo and behold the first one works fine going back and forth but the second one does not scroll after leaving and coming back.....

Code: Select all

global scrollid2

on preOpenCard
   if environment() is not "mobile" then exit preOpenCard
   put the rect of fld 1 into fldRect
   put the formattedHeight of fld 1 into fldHeight
   put the width of fld 1 into fldWidth
   
   set the height of fld 1 to fldHeight
   set the unboundedVScroll of group "scrollGroup" to true
   
   iphoneControlCreate "scroller"
   put the result into scrollid2
   
   iphoneControlSet scrollid2, "rect", fldRect
   iphoneControlSet scrollid2, "contentRect", (0, 0, fldWidth, fldHeight)
   iphoneControlSet scrollid2, "visible", "true"
   iphoneControlSet scrollid2, "canBounce", "true"
   iphoneControlSet scrollid2, "declerationRate", "fast"
   iphoneControlSet scrollid2, "scrollingEnabled", "true"
   iphoneControlSet scrollid2, "canScrollToTop", "true"
   iphoneControlSet scrollid2, "canCancelTouches", "false"
   iphoneControlSet scrollid2, "delayTouches", "true"
   iphoneControlSet scrollid2, "vIndicator", "true"
   iphoneControlSet scrollid2, "indicatorStyle", "black"
   iphoneControlSet scrollid2, "indicatorInsets",  "0,0,0,0"
   iphoneControlSet scrollid2, "hscroll", 0
   iphoneControlSet scrollid2, "vscroll", 0
   
   repeat with count = 1 to the number of lines of fld 1
      set the textShift of line count of fld 1 to - 10
   end repeat
   
   put the vScroll of group "scrollGroup" into fld 3
end preOpenCard

on closeCard
   //if environment() is not "mobile" then exit closeCard
   iphoneControlDelete scrollid2
end closeCard

on scrollerBeginDrag
   set the hilitedLine of fld 1 to empty
   put empty into fld 2
end scrollerBeginDrag

on scrollerScrollToTop
   iphoneControlSet scrollId2, "vscroll", 0
end scrollerScrollToTop

on scrollerDidScroll hOffset, vOffset
   set the vScroll of group "scrollGroup" to vOffset
   put vOffset into fld 3
end scrollerDidScroll

Re: Scroller not working after leaving card

Posted: Tue May 22, 2012 5:45 pm
by bn
Hi Djfuzion,

what I see is that you set the scroller to the formattedRect of field 1

Code: Select all

iphoneControlSet scrollid2, "rect", fldRect
iphoneControlSet scrollid2, "contentRect", (0, 0, fldWidth, fldHeight)
there is nothing to scroll since the scroller rect has the same dimensions as the contentRect. For the scroller nothing to scroll.

I took your example and played around with it and attach it here. 2 cards with the identicals card scripts and identical fields etc (I put them into a background group)
Not that I would do it this way but it works.

Could not attach the stack because of
Sorry, the board attachment quota has been reached.
here is the script of the cards (identical on both cards)

Code: Select all

global scrollid2

on preOpenCard
      if environment() is not "mobile" then exit preOpenCard
      put the rect of fld "scrollField" into fldRect
      put the formattedHeight of fld "scrollField" into fldHeight
      put the width of fld "scrollField" into fldWidth
      
      set the height of fld "scrollField" to fldHeight
   set the top of field "scrollField" to the top of group "scrollGroup"
   set the vScroll of group "scrollGroup" to 0
      set the unboundedVScroll of group "scrollGroup" to true
   
   
      
      iphoneControlCreate "scroller"
      put the result into scrollid2
      
      iphoneControlSet scrollid2, "rect", the rect of group "scrollGroup"
      iphoneControlSet scrollid2, "contentRect", (0, 0, fldWidth, fldHeight)
      iphoneControlSet scrollid2, "visible", "true"
      iphoneControlSet scrollid2, "canBounce", "true"
      iphoneControlSet scrollid2, "declerationRate", "fast"
      iphoneControlSet scrollid2, "scrollingEnabled", "true"
      iphoneControlSet scrollid2, "canScrollToTop", "true"
    iphoneControlSet scrollid2, "canCancelTouches", "true"
      iphoneControlSet scrollid2, "delayTouches", "true"
      iphoneControlSet scrollid2, "vIndicator", "true"
      iphoneControlSet scrollid2, "indicatorStyle", "black"
      iphoneControlSet scrollid2, "indicatorInsets",  "0,0,0,0"
      iphoneControlSet scrollid2, "hscroll", 0
      iphoneControlSet scrollid2, "vscroll", 0
      
      repeat with count = 1 to the number of lines of fld "scrollField"
            set the textShift of line count of fld 1 to - 5
      end repeat
      
   
      put the vScroll of group "scrollGroup" into fld 3
end preOpenCard

on closeCard
      if environment() is not "mobile" then exit closeCard
   set the vScroll of group "scrollGroup" to 0
   iphoneControlDelete scrollid2
end closeCard

on scrollerBeginDrag
   set the hilitedLine of fld 1 to empty
   put empty into fld 2
end scrollerBeginDrag

on scrollerScrollToTop
   iphoneControlSet scrollId2, "vscroll", 0
end scrollerScrollToTop

on scrollerDidScroll hOffset, vOffset
   set the vScroll of group "scrollGroup" to vOffset
   put vOffset into fld 3
end scrollerDidScroll

on errorDialog
   put the params into field "fErr"
end errorDialog
Kind regards

Bernd

Re: Scroller not working after leaving card

Posted: Wed May 23, 2012 9:49 am
by heatherlaine
Please ignore this post, I'm just testing the ability of the board to accept attachments.

Regards,

Heather
(Board Administrator)