×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Conflicting slider with Multiple Sprite Drag behavior, help!!!!! bua!!

Conflicting slider with Multiple Sprite Drag behavior, help!!!!! bua!!

Conflicting slider with Multiple Sprite Drag behavior, help!!!!! bua!!

(OP)
Hello everybody, I've been trying to solve a problem that at the beginnig looked simple, but after several hours of sleepless night, I've been becoming desperate and at the edge of a mental breakdown. I notice that the solution may not be simple, because I've posted in many forums and the answer have not been precisely clear.

The problem is this one, I have a slider which works fine until in all of its components the bevahoir MULTIPLE SPRITE DRAG is applied, now this behavior must be applied because I need to move the slider along with several members. But after the behavior is applied, the slider loose its functionality because when you want to move it, it drags all the members in the group. What can do in order to make the slider to keep working independently, but at the same to be "dragable" along with the group. I've already tried several things, including some weirds, and the only one that seems to work, but still needs some tweaks, is an idea from someone in a forum that recommend me to apply this small behavior in the pointer of the slider:

on mouseDown me
sendSprite sliderSpriteNum, #beginSprite
me

This works fine until you release the slider and click anywhere outside of it, and then when you try to move it again the maximum value for the position is changed for the last place the pointer was, that is to say, if you move the slider from 100 to 80 and release, click outside, try to move the slider again, it can not go up to 100 again, the maximum value, as possition, will be 80...and so on, and on. And if you move the slider to 0, it will give an error saying that it can not divide by 0. I guess this one is related with this part of the code of the slider:

x = the mouseH - pBounds.left
sliderRange = pBounds.right-pBounds.left
pos = float(x)/sliderRange

Well, I hope there is someone here who is willing to help me in this...now is almost a crusade, and I'm running out of time to finish the project currently I'm working on.

Suggestion, comments, help, whatever, will be highly appreciate it. I'm sending the code of the slider so you may have an idea of it. The code controls, the pointer, the shadow of the slider and text.

Thanks in advance.

property pPressed -- whether the sprite is being pressed
property pBounds -- the rect of the shadow sprite at start
property pShadowSprite -- the number of the shadow sprite
property pTextSprite -- the number of the text sprite
property pMinimumValue, pMaximumValue -- used by the marker sprite only
property pValue -- actual value of the slider

on getPropertyDescriptionList me
list = [:]
addProp list, #pShadowSprite, [#comment: "Shadow Sprite",\
#format: #integer, #default: 0]
addProp list, #pTextSprite, [#comment: "Text Sprite",\
#format: #integer, #default: 0]
addProp list, #pMinimumValue, [#comment: "Minimum Value",\
#format: #integer, #default: 0]
addProp list, #pMaximumValue, [#comment: "Maximum Value",\
#format: #integer, #default: 100]
addProp list, #pValue, [#comment: "Start Value",\
#format: #integer, #default: 100]
return list
end

on beginSprite me
pBounds = sprite(pShadowSprite).rect
setMarker(me)
setShadow(me)
setText(me)
end

on mouseDown me
pPressed = TRUE
end

on mouseUp me
pPressed = FALSE
end

on mouseUpOutside me
pPressed = FALSE
end

on exitFrame me
if pPressed then
moveMarker(me)
setMarker(me)
setShadow(me)
setText(me)
end if
end

-- this handler takes the mouse position and figures the
-- value of the slider
on moveMarker me
-- compute the position as a number between 0 and 1
x = the mouseH - pBounds.left
sliderRange = pBounds.right-pBounds.left
pos = float(x)/sliderRange

-- translate to a value
valueRange = pMaximumValue - pMinimumValue
pValue = pos*valueRange + pMinimumValue
pValue = integer(pValue)

-- check to make sure it is within bounds
if pValue > pMaximumValue then
pValue = pMaximumValue
else if pValue < pMinimumValue then
pValue = pMinimumValue
end if
end

-- this handler moves the marker one value left or right
on moveMarkerOne me, direction
if direction = #left then
pValue = pValue - 1
else if direction = #right then
pValue = pValue + 1
end if

-- check to make sure it is within bounds
if pValue > pMaximumValue then
pValue = pMaximumValue
else if pValue < pMinimumValue then
pValue = pMinimumValue
end if

setMarker(me)
setShadow(me)
setText(me)
end

-- this sets the marker sprite
on setMarker me
-- compute the value as a number between 0 and 1
valueRange = pMaximumValue - pMinimumValue
sliderPos = float(pValue)/float(valueRange)

-- translate to a screen position
sliderRange = pBounds.right-pBounds.left
x = sliderPos*sliderRange + pBounds.left

-- set marker
sprite(me.spriteNum).locH = x
end

-- this handler lets the marker sprite set the shadow sprite
on setShadow me
x = (sprite me.spriteNum).locH
r = rect(pBounds.left, pBounds.top, x, pBounds.bottom)
sprite(pShadowSprite).rect = r
end

-- this handler sets the text of the text sprite
on setText me
if pTextSprite <> 0 then -- is there a text sprite?
sprite(pTextSprite).member.text = string(pValue)
end if
end

-- this handler returns the value of the slider
on getValue me
return pValue
end

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close