13 Replies Latest reply on Jul 28, 2007 10:50 PM by wgb14

    (OSControl Xtra)How to detect when a user clicks down and when up

    wgb14 Level 1
      Hi All,

      How can I detect when i user clicks a scrollbar down and up? I want something like:

      If sprite(1).click(#down) then

      -- do something

      else

      if sprite(1).click(#up) then

      -- do something else


      Any ideas? The question applies only to the OS control xtra
        • 1. Re: (OSControl Xtra)How to detect when a user click down and   when   up
          Level 7
          From the docs:
          Clicking this control will send update calls to your sprite behavior
          each time the value of the sprite changes:
          on update me, partClicked
          … where partClicked can be #thumb, #up, #down, #pageUp or #pageDown.
          • 2. (OSControl Xtra)How to detect when a user click down and when up
            wgb14 Level 1
            I tried this script (based on docs) but it crashes director.... Any ideas?


            property pSprite

            on beginSprite(me)
            pSprite = sprite(me.spriteNum)
            end beginSprite


            on update

            if pSprite.click(#down) then

            alert ("down we go")

            end if


            end
            • 3. Re: (OSControl Xtra)How to detect when a user clicks down and when up
              wgb14 Level 1
              Ok, here is the partial answer to the problem

              on beginSprite(me)
              pSprite = sprite(me.spriteNum)
              end beginSprite


              on update(me, aClickedPart)


              case aClickedPart of

              (#up):


              timeout("scrollImage" & me.spriteNum).new(10, sendAllSprites(#scrollImage, -5), me)


              #down:

              timeout("scrollImage" & me.spriteNum).new(10, sendAllSprites(#scrollImage, 5), me)

              end case

              end

              My problem however is that i don't know how to sync the thumb of the scrollbar with the up and down actions. Any ideas?
              • 4. Re: (OSControl Xtra)How to detect when a user clicks   down and when   up
                Level 7
                > My problem however is that i don't know how to sync the thumb of the scrollbar
                > with the up and down actions. Any ideas?

                What do you mean by "sync"? Doesn't the thumb move automatically?
                Perhaps you could explain better what you expect to happen?
                Did you read the docs about value, maxValue and viewSize?
                • 5. Re: (OSControl Xtra)How to detect when a user clicks down and when up
                  wgb14 Level 1
                  No the thumb doesn't move automatically. What I am trying to do is to allow my user to move a sprite on my stage up and down using both the arrows and the thumb. At the moment my code works perfectly for the up and down arrows but not for the thumb. Any ideas how to fix this?
                  • 6. Re: (OSControl Xtra)How to detect when a user clicks   down and when   up
                    Level 7
                    When your sprite receives an #update message, and the part clicked is
                    the #thumb, query the value and compare against maxValue to decide how
                    much to scroll.
                    • 7. Re: (OSControl Xtra)How to detect when a user clicks down and when up
                      wgb14 Level 1
                      Hi sean thanks for the reply.... I am not sure how to do what you are suggesting... any more specific (code) examples? Many thanks
                      • 8. Re: (OSControl Xtra)How to detect when a user clicks down and when up
                        wgb14 Level 1
                        oK... here is the updated script... It works for thumb up but not for down... I am not sure what i am doing wrong... any ideas?

                        property pSprite
                        property pScrollAmt
                        global tMaxVal,maxbarvalue


                        on beginSprite(me)
                        pSprite = sprite(me.spriteNum)
                        end beginSprite

                        on prepareframe

                        pSprite.maxValue = maxbarvalue
                        pSprite.value = tMaxVal --position of the thumb
                        end

                        on update(me, aClickedPart)

                        CASE (aClickedPart) OF
                        #up:
                        timeout("scrollImage" & me.spriteNum).new(10, #sendScrollMessage, me)
                        pScrollAmt = -5

                        #down:
                        timeout("scrollImage" & me.spriteNum).new(10, #sendScrollMessage, me)
                        pScrollAmt = 5

                        END CASE

                        CASE (aClickedPart) OF

                        #thumb:

                        CASE TRUE OF
                        (tMaxVal > 0 AND tMaxVal < maxbarvalue): --1 - 867
                        timeout("scrollImage" & me.spriteNum).new(10, #sendScrollMessage, me)
                        pScrollAmt = 10 ---down
                        END CASE

                        CASE TRUE OF
                        (tMaxVal < maxbarvalue AND tMaxVal > 0 ): -- 867 -1
                        timeout("scrollImage" & me.spriteNum).new(10, #sendScrollMessage, me)
                        pScrollAmt = -10 --up
                        END CASE
                        END CASE
                        end
                        • 9. Re: (OSControl Xtra)How to detect when a user clicks   down and when   up
                          Level 7
                          > any more specific (code) examples?

                          Did you look on their site for demo files? If not, you should do so.
                          There is a single archive file with a number of individual movies - I
                          suggest ScrollSprite.dir would be a good place to start.
                          • 10. Re: (OSControl Xtra)How to detect when a user clicks down and when up
                            wgb14 Level 1
                            Hi,

                            As you can see above I solved almost all of the problems (consulting the movies that you are talking about). My only problem now is this thumb case statement. If you have any suggestions on how to modify it in order to make thumb down to work I would appreciate it...

                            Many thanks
                            • 11. Re: (OSControl Xtra)How to detect when a user clicks down and when up
                              wgb14 Level 1
                              To be more specific i must find a way to write a case statement that will know the difference between 0 to maxbarvalue(down) and maxbarvalue to 0 (up). The difference is in the order of the numbers. Any suggestions? please!
                              • 12. Re: (OSControl Xtra)How to detect when a user clicks   down and when   up
                                Level 7
                                I don't understand why you are setting the sprite.value and maxValue to
                                a global in a #prepareFrame event - can you explain why, and "who" it is
                                that's responsible for these values?
                                I have tried to "simplify" your script, but I don't have a clear picture
                                of what your problem is - can you perhaps post a pared-down example
                                somewhere that demonstrates it clearly?
                                --
                                property pSprite
                                property pScrollAmt
                                global tMaxVal,maxbarvalue

                                on beginSprite(me)
                                pSprite = sprite(me.spriteNum)
                                end beginSprite

                                on prepareframe
                                pSprite.maxValue = maxbarvalue
                                pSprite.value = tMaxVal --position of the thumb
                                end

                                on update(me, aClickedPart)

                                CASE (aClickedPart) OF
                                #up:
                                pScrollAmt = -5

                                #down:
                                pScrollAmt = 5

                                #thumb:
                                if pSprite.value < tMaxVal then pScrollAmt = -10
                                else if pSprite.value > tMaxVal then pScrollAmt = 10
                                else exit
                                END CASE

                                -- it's important to "catch" the value returned when creating a
                                -- timeout object, even if it's into a local variable that will
                                -- immediately go out of scope
                                t = timeout("scrollImage"&me.spriteNum).new(10,#sendScrollMessage, me)
                                end
                                • 13. Re: (OSControl Xtra)How to detect when a user clicks down and when up
                                  wgb14 Level 1
                                  Hi Sean,

                                  Thanks it is working now: Here is the full code (it is a thumbnaile broweser). if you think you can make any improvements let me know

                                  property pSprite
                                  PROPERTY pScrollAmt
                                  global tMaxVal,maxthumbvalue

                                  on beginSprite(me)
                                  pSprite = sprite(me.spriteNum)
                                  end beginSprite

                                  on prepareframe

                                  pSprite.value = tMaxVal --position of the thumb
                                  pSprite.maxValue = maxthumbvalue --scale of the scrollbar
                                  end

                                  on update(me, aClickedPart)

                                  CASE (aClickedPart) OF

                                  #up:

                                  pScrollAmt = -10

                                  #down:
                                  pScrollAmt = 10

                                  #thumb:

                                  if pSprite.value < tMaxVal then pScrollAmt = -10
                                  else if pSprite.value > tMaxVal then pScrollAmt = 10
                                  else exit

                                  END CASE

                                  t = timeout("scrollImage"&me.spriteNum).new(10,sendAllSprites(#scrollImage, pScrollAmt), me)

                                  end update

                                  on mouseUp me
                                  timeout("scrollImage" & me.spriteNum).forget()
                                  end

                                  on mouseUpOutside me
                                  timeout("scrollImage" & me.spriteNum).forget()
                                  end

                                  on endSprite me
                                  timeout("scrollImage" & me.spriteNum).forget()
                                  end
                                  ------------------------------------------------

                                  -- picture mamanger behaviour

                                  property pImageList
                                  property pRectList
                                  property pFileList
                                  global tMaxVal,maxthumbvalue
                                  property pFullImage
                                  property pVerticalOffset
                                  property pThumbImage
                                  -- user defined props
                                  property pSource
                                  property pMaxHeightOrWidth
                                  property pHorizontalSpacing
                                  property pVerticalSpacing
                                  property pImagesAcross
                                  property pFullScreenHeightOrWidth

                                  property pVisibleHeight

                                  on beginSprite me
                                  pFullImage = false
                                  pVerticalOffset = 0
                                  me.buildImageList()
                                  me.createImage()
                                  end

                                  on getPropertyDescriptionList
                                  props = [:]

                                  sourceList = ["external images folder"]
                                  repeat with i = 1 to the number of castlibs
                                  sourceList.append(the name of castlib i && "cast")
                                  end repeat

                                  props.addProp(#pSource, [#format:#string, #default: "external images folder", #comment: "Select source of images:", #range:sourceList])

                                  props.addProp(#pMaxHeightOrWidth, [#format:#integer, #default:80, #comment: "Enter the maximum height/width of your thumbnails:"])
                                  props.addProp(#pHorizontalSpacing, [#format:#integer, #default:20, #comment: "Enter the number of horizontal pixels between each of your thumbnails:"])
                                  props.addProp(#pVerticalSpacing, [#format:#integer, #default:20, #comment: "Enter the number of vertical pixels between each of your thumbnails:"])
                                  props.addProp(#pImagesAcross, [#format:#integer, #default:3, #comment: "Enter the maximum number of thumbnails to appear across the screen:"])


                                  props.addProp(#pVisibleHeight, [#format:#integer, #default:300, #comment: "Enter the height of the thumbnail display:"])

                                  return props
                                  end

                                  on buildImageList me
                                  pImageList = []
                                  pFileList = []

                                  if pSource = "external images folder" then
                                  if the platform contains "Windows" then
                                  imagePath = the moviePath & "images\Background\"
                                  else
                                  imagePath = the moviePath & "images:"
                                  end if

                                  repeat with i = 1 to 10000
                                  imageName = getNthFileNameInFolder(imagePath, i)
                                  if imageName = EMPTY then
                                  exit repeat
                                  else
                                  member("imageHolder").filename = imagePath & imageName
                                  updateStage

                                  fileTypes = [".bmp", ".pct", ".jpg", ".gif"]
                                  howManyTypes = count(fileTypes)
                                  repeat with thisType = 1 to howManyTypes
                                  extension = getAt(fileTypes, thisType)
                                  if imageName contains extension then
                                  pImageList.append(member("imageHolder").image.duplicate())
                                  pFileList.append(imageName)
                                  end if
                                  end repeat
                                  end if
                                  end repeat
                                  else
                                  castName = pSource.char[1..(pSource.char.count - 4)]
                                  repeat with i = 1 to (the number of members of castlib castName)
                                  if member(i, castName).type = #bitmap then
                                  pImageList.append(member(i, castName).image.duplicate())
                                  pFileList.append(member(i, castName).name)
                                  end if
                                  end repeat
                                  end if
                                  end

                                  on mouseDown me

                                  repeat with i = 1 to pRectList.count
                                  if (the clickLoc - sprite(me.spriteNum).loc).inside(pRectList .offset(0, - pVerticalOffset)) then
                                  imagepath = "@\images\Background\"
                                  window("Haptek_player").movie.sprite(1).Hypertext ="\loadbackground [file= ["&imagepath&" & "&pFileList
                                  &"] ]"
                                  end if
                                  end repeat

                                  end

                                  on mousewithin me

                                  repeat with i = 1 to pRectList.count
                                  if (the mouseLoc - sprite(me.spriteNum).loc).inside(pRectList .offset(0, - pVerticalOffset)) then
                                  put pFileList
                                  into member("info1")
                                  put "Size:" && pImageList .width &"x"& pImageList.height into member("info2")

                                  end if
                                  end repeat

                                  end mousewithin me

                                  on createImage me -- master image of thumbnails

                                  masterImageWidth = (pImagesAcross * pMaxHeightOrWidth) + ((pImagesAcross + 1) * pHorizontalSpacing)

                                  numberOfRows = pImageList.count / pImagesAcross
                                  if ((pImageList.count mod pImagesAcross) <> 0) then
                                  numberOfRows = numberOfRows + 1
                                  end if

                                  masterImageHeight = (numberOfRows * pMaxHeightOrWidth) + ((numberOfRows + 1) * pVerticalSpacing)
                                  pThumbImage = image(masterImageWidth, masterImageHeight, 16)

                                  pRectList = []
                                  rowCount = 1
                                  colCount = 1

                                  repeat with i = 1 to pImageList.count
                                  tempH = (colCount * pHorizontalSpacing) + ((colCount - 1) * pMaxHeightOrWidth)
                                  tempV = (rowCount * pVerticalSpacing) + ((rowCount - 1) * pMaxHeightOrWidth)

                                  if pImageList .width > pImageList.height then
                                  -- it's a landscape image
                                  newHeight = (pImageList .height * pMaxHeightOrWidth) / pImageList.width
                                  tempV = tempV + ((pMaxHeightOrWidth - newHeight)/2)
                                  destRect = rect(tempH, tempV, tempH + pMaxHeightOrWidth, tempV + newHeight)
                                  else
                                  -- it's a portrait image
                                  newWidth = (pImageList .width * pMaxHeightOrWidth) / pImageList.height
                                  tempH = tempH + ((pMaxHeightOrWidth - newWidth)/2)
                                  destRect = rect(tempH, tempV, tempH + newWidth, tempV + pMaxHeightOrWidth)
                                  end if

                                  pRectList = destRect
                                  pThumbImage.copyPixels(pImageList
                                  , destRect, pImageList .rect)

                                  colCount = colCount + 1
                                  if colCount > pImagesAcross then
                                  colCount = 1
                                  rowCount = rowCount + 1
                                  end if
                                  end repeat
                                  me.displayThumbnailImage()

                                  end

                                  on displayThumbnailImage me --controls the drawing of all the thumbnails on screen.

                                  pfullImage = false
                                  tempImage = image(pThumbImage.width, pVisibleHeight, 16)
                                  imageSourceRect = rect(0, pVerticalOffset, pThumbImage.width , pVerticalOffset + pVisibleHeight)
                                  tempImage.copyPixels(pThumbImage, tempImage.rect, imageSourceRect)
                                  sprite(me.spriteNum).member.image = tempImage
                                  sprite(me.spriteNum).member.regPoint = point(0,0)
                                  maxthumbvalue = (pThumbImage.height-pVisibleHeight) + 10
                                  tMaxVal = min(pVerticalOffset, pThumbImage.height - pVisibleHeight)
                                  updateStage
                                  end


                                  on scrollImage me, howMuchToScroll

                                  pVerticalOffset = max(0, pVerticalOffset + howMuchToScroll) -- from top to bottom
                                  pVerticalOffset = min(pVerticalOffset, pThumbImage.height - pVisibleHeight) --maximum amount you can scroll
                                  me.displayThumbnailImage()
                                  end