Ask a Question related to Macromedia Director Lingo, Design and Development.

  1. #1

    Default bounding box?

    I have a sprite that follows the mouse and I need it to stop at all edges of the stage and not go off the side. the stage is 1024x768, but i have a menu at the bottom so it needs to be a little aboe the bottom of the stage (about 90 pixels).

    i know that it can be done, but i don't know how to go about it. thanks.



    adams2003 webforumsuser@macromedia.com Guest

  2. Similar Questions and Discussions

    1. keep bounding box in transform tool?
      I'll probably feel stupid for never figuring this out, but I've been fudging with this for years, and can't seem to find any info on this in the help...
    2. Unable to set bounding box
      I am trying to resize group objects but get the message Unable to set bounding box. I have tried to resize as a group and as individual objects...
    3. BUG: resize with bounding box?
      I have noticed that objects no longer display a bounding box. This means I cannot resize or rotate using the selection tool. Is this a bug? How...
    4. event rollover with bounding box
      I have a simple button I wanna know how to make it so when you rollover the button a little mc box appears near the button and the mc box moves with...
    5. Bounding Box problem
      I am creating a shape and want to save it as a bitmap file, but I can't eliminate the white areas in the bounding box outside of the shape which is a...
  3. #2

    Default Re: bounding box?


    attach this behaviour to your sprite:


    property spriteNum

    on exitFrame me

    stageWidth = the stageRight- the stageLeft
    stageHeight = (the stageBottom - 90) - the stageTop
    leftAdj = sprite(spriteNum).locH - sprite(spriteNum).left
    rightAdj = sprite(spriteNum).locH - sprite(spriteNum).right
    topAdj = sprite(spriteNum).locV - sprite(spriteNum).top
    bottomAdj = sprite(spriteNum).locV - sprite(spriteNum).bottom

    newLoc = the mouseLoc

    if (newLoc.locH > stageWidth + rightAdj) then
    newLoc.locH = stageWidth + rightAdj
    else if (newLoc.locH < 0 + leftAdj) then
    newLoc.locH = 0 + leftAdj
    end if
    if (newLoc.locV > stageHeight + bottomAdj) then
    newLoc.locv = stageHeight + bottomAdj
    else if (newLoc.locV < 0 + topAdj) then
    newLoc.locV = 0 + topAdj
    end if

    sprite(spriteNum).loc = newLoc

    updateStage

    end
    Christian Grass Guest

  4. #3

    Default Re: bounding box?


    attach this behaviour to your sprite:


    property spriteNum

    on exitFrame me

    stageWidth = the stageRight- the stageLeft
    stageHeight = (the stageBottom - 90) - the stageTop
    leftAdj = sprite(spriteNum).locH - sprite(spriteNum).left
    rightAdj = sprite(spriteNum).locH - sprite(spriteNum).right
    topAdj = sprite(spriteNum).locV - sprite(spriteNum).top
    bottomAdj = sprite(spriteNum).locV - sprite(spriteNum).bottom

    newLoc = the mouseLoc

    if (newLoc.locH > stageWidth + rightAdj) then
    newLoc.locH = stageWidth + rightAdj
    else if (newLoc.locH < 0 + leftAdj) then
    newLoc.locH = 0 + leftAdj
    end if
    if (newLoc.locV > stageHeight + bottomAdj) then
    newLoc.locv = stageHeight + bottomAdj
    else if (newLoc.locV < 0 + topAdj) then
    newLoc.locV = 0 + topAdj
    end if

    sprite(spriteNum).loc = newLoc

    updateStage

    end
    Christian Grass Guest

  5. #4

    Default Re: bounding box?

    thanks for the help. it works somewhat. it bounces real bad once you move the mouse out of the bounding box. is there a way to make the metal detecter not follow the mouse until it gets within the stage? because right now i still can't click on the menu buttons because the metal detector gets in the way.

    here is a working example. please choose the lake because the yard isn't working yet.

    [url]http://myweb.cableone.net/badams1/12-7.htm[/url]

    thanks again.



    adams2003 webforumsuser@macromedia.com Guest

  6. #5

    Default Re: bounding box? -- this should work


    I just found out that there's a pre-defined behaviour shipped with
    director. It's under the section "animation" in the "library palette"
    window and is called "constrain to sprite". just drag this on your sprite.

    chris
    Christian Grass Guest

  7. #6

    Default Re: bounding box? -- this should work

    well i couldn't get that one to work. it kept giving me some error message. but i did use sprite track mouse which won't let it go off of the stage, but i don't know what to edit to keep it from going in the menu area. i'm posting the code here and hopefully someone can tell me what to edit to keep the sprite 120 pixels from the bottom of the stage.

    on getBehaviorDescription me
    return \
    "SPRITE TRACK MOUSE" & RETURN & RETURN & \
    "This behavior will move a sprite so that it is under the cursor. " & \
    "The sprite will appear with its registration point or center under the cursor's hotspot." & RETURN & RETURN & \
    "PERMITTED MEMBER TYPES:" & RETURN & \
    "Graphic members" & RETURN & RETURN & \
    "PARAMETERS:" & RETURN & \
    "* Center sprite on cursor" & RETURN & \
    "* Limited to stage area"
    end getBehaviorDescription


    on getBehaviorTooltip me
    return \
    "Makes a sprite move to follow the cursor around the stage so that the center of the sprite is under the cursor."
    end getBehaviorTooltip


    -- PROPERTIES --

    property pSprite -- sprite channel number
    property pStageBounds -- stage boundary values
    -- author-defined parameters
    property pCentered -- use sprite cente or loc
    property pLimited -- limit movement to stage area

    -- EVENT HANDLERS

    on beginSprite me
    mInitialize me
    end beginSprite

    on prepareFrame me
    mUpdate me
    end prepareFrame

    -- CUSTOM HANDLERS --

    on mCenter vRect
    -- returns point value representing center of rectangle
    vHalfWidth = vRect.width / 2
    vHalfHeight = vRect.height / 2
    return point (vRect.left + vHalfWidth, vRect.top + vHalfHeight)
    end mCenter

    on mCenterOffset
    -- returns vector for difference between center of sprite and loc;
    -- used to ensure compatibility with text, vector, and shape sprites
    -- as well as bitmaps with offset loc values
    vCenter = mCenter (sprite (pSprite).rect)
    return vCenter - sprite (pSprite).loc
    end mCenterOffset

    on mCenteredRect vPoint, vRect
    --returns a rect centered on point vPoint
    vWidth = vRect.width
    vHeight = vRect.height
    vHalfWidth = vWidth / 2
    vHalfHeight = vHeight / 2
    vLeft = vPoint.locH - vHalfWidth
    vTop = vPoint.locV - vHalfHeight
    return rect (vLeft, vTop, vLeft + vWidth, vTop + vHeight)
    end mCenteredRect

    on mInitialize me
    -- called from beginsprite
    -- sets initial values for all conditions
    pSprite = me.spriteNum
    pStageBounds = point (the stage.rect.width, the stage.rect.height)
    end mInitialize

    on mStageLimit vRect
    --returns rect limited to stage area
    if vRect.left < 0 then vOffsetH = -vRect.left
    else vOffsetH = min (0, pStageBounds.locH - vRect.right)
    if vRect.top < 0 then vOffsetV = -vRect.top
    else vOffsetV = min (0, pStageBounds.locV - vRect.bottom)
    return offset (vRect, vOffsetH, vOffsetV)
    end mStageLimit

    on mUpdate me
    -- called from prepereFrame handler
    -- moves sprite to position under cursor
    if pCentered then
    vRect = mCenteredRect (the mouseLoc, sprite (pSprite).rect)
    else
    vRect = mCenteredRect (the mouseLoc + \
    mCenterOffset (), sprite (pSprite).rect)
    end if
    if pLimited then vRect = mStageLimit (vRect)
    sprite (pSprite).rect = vRect
    end mUpdate

    -- PUBLIC METHODS --
    --Examples:
    -- on exitFrame
    -- sendSprite(whichSprite, #mSetCentered, vBool)
    -- end
    --
    --in which whichSprite is the number of the sprite for which
    --youwant to "turn on" tracking, and vBool is a boolean
    --value of either TRUE or FALSE
    --
    -- on mouseUp
    -- sendSprite(whichSprite, #mSetLimited, vBool)
    -- end
    --
    -- on mouseDown
    -- sendSprite(whichSprite, #mToggleCentered, vBool)
    -- end
    --
    -- on myCustomHandler
    -- sendSprite(whichSprite, #mToggleLimited, vBool)
    -- end myCustomHandler

    on mSetCentered me, vBool
    -- can be sent as message to sprite to determine whether
    -- sprite position is based on center or loc;
    -- if pCentered is TRUE, sprite is centered on cursor,
    -- otherwise sprite's loc is under cursor
    if not (not (vBool)) = vBool then
    pCentered = vBool
    end if
    end mSetCentered

    on mSetLimited me, vBool
    -- can be sent as message to sprite to determine whether
    -- sprite position is limited to stage rect;
    -- pLimited = TRUE means sprite won't move off stage
    if not (not (vBool)) = vBool then
    pLimited = vBool
    end if
    end mSetLimited

    on mToggleCentered me
    -- similar to mSetCentered but simply toggles boolean value
    pCentered = not pCentered
    end mToggleCentered

    on mToggleLimited me
    -- similar to mSetLimited but simply toggles boolean value
    pLimited = not pLimited
    end mToggleLimited

    -- AUTHOR-DEFINED PARAMETERS --

    on isOKToAttach (me, aSpriteType, aSpriteNum)
    case aSpriteType of
    #graphic:
    return getpos([#quickTimeMedia, #flash, #digitalvideo], sprite(aSpriteNum).member.type) = 0
    #script:
    return FALSE
    end case
    end isOKToAttach


    on getPropertyDescriptionList
    vPDList = [:]
    setaProp vPDList, #pCentered, [#comment: \
    "Center sprite on cursor (alternative is to use loc)", \
    #format: #boolean, #default: TRUE]
    setaProp vPDList, #pLimited, [#comment: "Limited to stage area", \
    #format: #boolean, #default: TRUE]
    return vPDList
    end getPropertyDescriptionList


    adams2003 webforumsuser@macromedia.com Guest

  8. #7

    Default Re: bounding box? -- this should work


    Well, when I tried the pre-defined behaviour I used two sprites: the
    sprite that should be constrained and a rectangular shape as the bounding
    sprite. This worked really great, as you can fit this rectangular with its
    size and position to the desired bounding area.

    I copy-pasted your code and tried it. I recognized that this was not the
    behaviour I was talking about. The behaviour I was talking about uses two
    sprites: one to constrain the other and the sprite that is to be dragged
    around. I just adjusted the constraining sprite to the stage area. In your
    case a little bit resized at the bottom.

    Just to get sure, here's the code. I would be interested if this worked!

    ----------------------------------------------


    -- PROPERTIES --

    property pAlertFlag -- used to control the appearance of error
    alert messages
    property pSprite -- constrained sprite reference
    property pOffset -- offset of mouse click from sprite origin
    property pActive -- activity flag for sprite dragging
    -- author-defined properties
    property pConstrainSprite -- constrain sprite channel
    property pDraggable -- flag for sprite drag ability

    -- EVENT HANDLERS --

    on beginSprite me
    pAlertFlag = FALSE
    -- cache sprite reference
    pSprite = sprite (me.spriteNum)
    end beginSprite

    on prepareFrame me
    mUpdate me
    end prepareFrame

    on mouseDown me
    -- if mouse is clicked, prepeare for dragging, if needed
    if pDraggable then
    -- set dragging activity flag
    pActive = TRUE
    -- determine offset of click from top left corner of sprite
    pOffset = point (pSprite.rect.left, pSprite.rect.top) - the clickLoc
    end if
    end mouseDown

    -- CUSTOM HANDLERS --

    on mUpdate me
    -- determine current constraint rectangle
    -- allows for moving or changing constraint sprites
    vConstrainRect = sprite (pConstrainSprite).rect
    -- find size of current sprite rect
    vRect = rect (0, 0, pSprite.member.rect.width, \
    pSprite.member.rect.height)
    -- test to see if the constraining rect is too small
    -- in either dimension to contain the constrained rect
    if (vConstrainRect.width < vRect.width) or \
    (vConstrainRect.height < vRect.height) then
    mErrorAlert me, #tooSmall, me.spriteNum
    else
    pAlertFlag = FALSE
    -- find current rect of sprite
    vNewRect = pSprite.rect
    -- check to see if sprite is being dragged
    if pActive then
    if the mouseDown then
    -- find the point defined by the cursor position
    -- and the offset value determined when the sprite was clicked
    -- to define where the top left corner of the sprite should be
    vNewLoc = the mouseLoc + pOffset
    -- offset rect of sprite's size by where the top
    -- left corner should go
    vNewRect = offset(vRect, vNewLoc.locH, vNewLoc.locV)
    else
    -- if the flag is set but the mouse button has been released,
    -- turn of the dragger flag
    pActive = FALSE
    end if
    end if
    -- find intersection of constraining sprite and constrained sprite
    vIntersect = intersect (vNewRect, vConstrainRect)
    -- test to see if the intersection is the same size as the new rect;
    -- if it is, then the new rect fits inside the constraint, if not,
    -- the new rect must be moved to fit
    if vIntersect <> vNewRect then
    vNewRect = mRestrictRect (vNewRect, vConstrainRect)
    end if
    -- change the sprite rect to match the newly determined rect
    pSprite.rect = mRestrictRect (vNewRect, vConstrainRect)
    end if
    end mUpdate

    on mRestrictRect vRestrictedRect, vRect
    -- finds the closest rectangle to vRestrictedRect within vRect
    -- assumes that vRect is large enough to contain vRestrictedRect
    -- determine the difference between the two rects
    vDiffRect = vRect - vRestrictedRect
    -- test the four sides of the rectangles and shift the position
    -- of the restricted rectangle by the appropriate amounts
    if vDiffRect.left > 0 then vRestrictedRect = \
    offset (vRestrictedRect, vDiffRect.left, 0)
    if vDiffRect.top > 0 then vRestrictedRect = \
    offset (vRestrictedRect, 0, vDiffRect.top)
    if vDiffRect.right < 0 then vRestrictedRect = \
    offset (vRestrictedRect, vDiffRect.right, 0)
    if vDiffRect.bottom < 0 then vRestrictedRect = \
    offset (vRestrictedRect, 0, vDiffRect.bottom)
    return vRestrictedRect
    end mRestrictRect

    on mConstraintSpriteList vSprite
    -- builds list of valid constraint sprites for property
    -- description list handler
    -- initialize sprite list
    vSpriteList = []
    -- derive rect of selected sprite
    vSpriteRect = sprite (vSprite).rect
    -- test all channels in movie
    repeat with i = 1 to the lastChannel
    -- test to see if there's a sprite in the channel
    if sprite (i).type then
    -- eliminate the current sprite channel
    if i <> vSprite then
    -- test the rect of the current sprite against each
    -- of the detected sprites to see if they can contain
    -- the current sprite and are correctly positioned
    -- and add them to the list
    if (intersect (sprite (i).rect, vSpriteRect) = \
    vSpriteRect) then
    add vSpriteList, i
    end if
    end if
    end if
    end repeat
    return vSpriteList
    end mVideoSpriteList

    -- ERROR CHECKING --

    on mErrorAlert me, vError, vData
    -- based on James Newton's error checking procedure
    -- determine name of behavior
    vBehaviorname = string (me)
    delete word 1 of vBehaviorName
    delete the last word of vBehaviorName
    delete the last word of vBehaviorName
    -- convert supporting data
    case vData.ilk of
    #void: vData = "<void>"
    #symbol: vData = "#" & vData
    end case
    case vError of -- deal with individual error types
    #noConstraints: -- called if no constraints are detected
    message = substituteStrings("Es liegen keine Sprites vor, die größer
    sind als das beschränkte Sprite, oder das beschränkte Sprite bedeckt ein
    größeres Sprite nicht ganz.", \
    ["^1": vBehaviorname, "^2": vData, "^3": the frame])
    #tooSmall: -- called if no constraint sprite is too small
    message = substituteStrings("VERHALTEN: ^1" & RETURN & \
    "Sprite ^2, Bild^3" & RETURN & RETURN & \
    "Das beschränkende Sprite muss größer sein als das beschränkte
    Sprite.", \
    ["^1": vBehaviorname, "^2": vData, "^3": the frame])
    end case
    if (the runMode = "Author") then
    alert message
    halt
    else if (the runMode = "Projector") then
    if (pAlertFlag = FALSE) then
    alert message
    pAlertFlag = TRUE
    end if
    end if
    end mErrorAlert


    on substituteStrings(parentString, childStringList) --------------
    --
    -- * Modifies parentString so that the strings which appear as
    -- properties in childStringList are replaced by the values
    -- associated with those properties.
    --
    -- <childStringList> has the format ["^1": "replacement string"]
    --------------------------------------------------------------------

    i = childStringList.count()
    repeat while i
    tempString = ""
    dummyString = childStringList.getPropAt(i)
    replacement = childStringList[i]
    lengthAdjust = dummyString.char.count - 1
    repeat while TRUE
    position = offset(dummyString, parentString)
    if not position then
    parentString = tempString&parentString
    exit repeat
    else
    if position <> 1 then
    tempString = tempString&parentString.char[1..position - 1]
    end if
    tempString = tempString&replacement
    delete parentString.char[1..position + lengthAdjust]
    end if
    end repeat
    i = i - 1
    end repeat

    return parentString
    end substituteStrings


    -- AUTHOR-DEFINED PARAMETERS --
    on isOKToAttach (me, aSpriteType, aSpriteNum)
    return aSpriteType = #Graphic
    end


    on getPropertyDescriptionList me
    if not the currentSpriteNum then
    -- behavior has been attached to script channel
    exit
    end if
    -- build video sprite list
    vConstraintSprites = mConstraintSpriteList (the currentSpriteNum)
    if not vConstraintSprites.count then
    -- call error regarding no valid constraining sprites
    return mErrorAlert (me, #noConstraints, the currentSpriteNum)
    else
    vPDList = [:]
    setaProp vPDList, #pConstrainSprite, [#comment: "Channel of the Sprite
    that provides the bounds:", \
    #format: #integer, #default: vConstraintSprites[1], #range:
    vConstraintSprites]
    setaProp vPDList, #pDraggable, [#comment: "Constrained Sprite
    draggable?", \
    #format: #boolean, #default: TRUE]
    return vPDList
    end if
    end getPropertyDescriptionList
    Christian Grass Guest

  9. #8

    Default Re: bounding box? -- this should work


    Well, when I tried the pre-defined behaviour I used two sprites: the
    sprite that should be constrained and a rectangular shape as the bounding
    sprite. This worked really great, as you can fit this rectangular with its
    size and position to the desired bounding area.

    I copy-pasted your code and tried it. I recognized that this was not the
    behaviour I was talking about. The behaviour I was talking about uses two
    sprites: one to constrain the other and the sprite that is to be dragged
    around. I just adjusted the constraining sprite to the stage area. In your
    case a little bit resized at the bottom.

    Just to get sure, here's the code. I would be interested if this worked!

    ----------------------------------------------


    -- PROPERTIES --

    property pAlertFlag -- used to control the appearance of error
    alert messages
    property pSprite -- constrained sprite reference
    property pOffset -- offset of mouse click from sprite origin
    property pActive -- activity flag for sprite dragging
    -- author-defined properties
    property pConstrainSprite -- constrain sprite channel
    property pDraggable -- flag for sprite drag ability

    -- EVENT HANDLERS --

    on beginSprite me
    pAlertFlag = FALSE
    -- cache sprite reference
    pSprite = sprite (me.spriteNum)
    end beginSprite

    on prepareFrame me
    mUpdate me
    end prepareFrame

    on mouseDown me
    -- if mouse is clicked, prepeare for dragging, if needed
    if pDraggable then
    -- set dragging activity flag
    pActive = TRUE
    -- determine offset of click from top left corner of sprite
    pOffset = point (pSprite.rect.left, pSprite.rect.top) - the clickLoc
    end if
    end mouseDown

    -- CUSTOM HANDLERS --

    on mUpdate me
    -- determine current constraint rectangle
    -- allows for moving or changing constraint sprites
    vConstrainRect = sprite (pConstrainSprite).rect
    -- find size of current sprite rect
    vRect = rect (0, 0, pSprite.member.rect.width, \
    pSprite.member.rect.height)
    -- test to see if the constraining rect is too small
    -- in either dimension to contain the constrained rect
    if (vConstrainRect.width < vRect.width) or \
    (vConstrainRect.height < vRect.height) then
    mErrorAlert me, #tooSmall, me.spriteNum
    else
    pAlertFlag = FALSE
    -- find current rect of sprite
    vNewRect = pSprite.rect
    -- check to see if sprite is being dragged
    if pActive then
    if the mouseDown then
    -- find the point defined by the cursor position
    -- and the offset value determined when the sprite was clicked
    -- to define where the top left corner of the sprite should be
    vNewLoc = the mouseLoc + pOffset
    -- offset rect of sprite's size by where the top
    -- left corner should go
    vNewRect = offset(vRect, vNewLoc.locH, vNewLoc.locV)
    else
    -- if the flag is set but the mouse button has been released,
    -- turn of the dragger flag
    pActive = FALSE
    end if
    end if
    -- find intersection of constraining sprite and constrained sprite
    vIntersect = intersect (vNewRect, vConstrainRect)
    -- test to see if the intersection is the same size as the new rect;
    -- if it is, then the new rect fits inside the constraint, if not,
    -- the new rect must be moved to fit
    if vIntersect <> vNewRect then
    vNewRect = mRestrictRect (vNewRect, vConstrainRect)
    end if
    -- change the sprite rect to match the newly determined rect
    pSprite.rect = mRestrictRect (vNewRect, vConstrainRect)
    end if
    end mUpdate

    on mRestrictRect vRestrictedRect, vRect
    -- finds the closest rectangle to vRestrictedRect within vRect
    -- assumes that vRect is large enough to contain vRestrictedRect
    -- determine the difference between the two rects
    vDiffRect = vRect - vRestrictedRect
    -- test the four sides of the rectangles and shift the position
    -- of the restricted rectangle by the appropriate amounts
    if vDiffRect.left > 0 then vRestrictedRect = \
    offset (vRestrictedRect, vDiffRect.left, 0)
    if vDiffRect.top > 0 then vRestrictedRect = \
    offset (vRestrictedRect, 0, vDiffRect.top)
    if vDiffRect.right < 0 then vRestrictedRect = \
    offset (vRestrictedRect, vDiffRect.right, 0)
    if vDiffRect.bottom < 0 then vRestrictedRect = \
    offset (vRestrictedRect, 0, vDiffRect.bottom)
    return vRestrictedRect
    end mRestrictRect

    on mConstraintSpriteList vSprite
    -- builds list of valid constraint sprites for property
    -- description list handler
    -- initialize sprite list
    vSpriteList = []
    -- derive rect of selected sprite
    vSpriteRect = sprite (vSprite).rect
    -- test all channels in movie
    repeat with i = 1 to the lastChannel
    -- test to see if there's a sprite in the channel
    if sprite (i).type then
    -- eliminate the current sprite channel
    if i <> vSprite then
    -- test the rect of the current sprite against each
    -- of the detected sprites to see if they can contain
    -- the current sprite and are correctly positioned
    -- and add them to the list
    if (intersect (sprite (i).rect, vSpriteRect) = \
    vSpriteRect) then
    add vSpriteList, i
    end if
    end if
    end if
    end repeat
    return vSpriteList
    end mVideoSpriteList

    -- ERROR CHECKING --

    on mErrorAlert me, vError, vData
    -- based on James Newton's error checking procedure
    -- determine name of behavior
    vBehaviorname = string (me)
    delete word 1 of vBehaviorName
    delete the last word of vBehaviorName
    delete the last word of vBehaviorName
    -- convert supporting data
    case vData.ilk of
    #void: vData = "<void>"
    #symbol: vData = "#" & vData
    end case
    case vError of -- deal with individual error types
    #noConstraints: -- called if no constraints are detected
    message = substituteStrings("Es liegen keine Sprites vor, die größer
    sind als das beschränkte Sprite, oder das beschränkte Sprite bedeckt ein
    größeres Sprite nicht ganz.", \
    ["^1": vBehaviorname, "^2": vData, "^3": the frame])
    #tooSmall: -- called if no constraint sprite is too small
    message = substituteStrings("VERHALTEN: ^1" & RETURN & \
    "Sprite ^2, Bild^3" & RETURN & RETURN & \
    "Das beschränkende Sprite muss größer sein als das beschränkte
    Sprite.", \
    ["^1": vBehaviorname, "^2": vData, "^3": the frame])
    end case
    if (the runMode = "Author") then
    alert message
    halt
    else if (the runMode = "Projector") then
    if (pAlertFlag = FALSE) then
    alert message
    pAlertFlag = TRUE
    end if
    end if
    end mErrorAlert


    on substituteStrings(parentString, childStringList) --------------
    --
    -- * Modifies parentString so that the strings which appear as
    -- properties in childStringList are replaced by the values
    -- associated with those properties.
    --
    -- <childStringList> has the format ["^1": "replacement string"]
    --------------------------------------------------------------------

    i = childStringList.count()
    repeat while i
    tempString = ""
    dummyString = childStringList.getPropAt(i)
    replacement = childStringList[i]
    lengthAdjust = dummyString.char.count - 1
    repeat while TRUE
    position = offset(dummyString, parentString)
    if not position then
    parentString = tempString&parentString
    exit repeat
    else
    if position <> 1 then
    tempString = tempString&parentString.char[1..position - 1]
    end if
    tempString = tempString&replacement
    delete parentString.char[1..position + lengthAdjust]
    end if
    end repeat
    i = i - 1
    end repeat

    return parentString
    end substituteStrings


    -- AUTHOR-DEFINED PARAMETERS --
    on isOKToAttach (me, aSpriteType, aSpriteNum)
    return aSpriteType = #Graphic
    end


    on getPropertyDescriptionList me
    if not the currentSpriteNum then
    -- behavior has been attached to script channel
    exit
    end if
    -- build video sprite list
    vConstraintSprites = mConstraintSpriteList (the currentSpriteNum)
    if not vConstraintSprites.count then
    -- call error regarding no valid constraining sprites
    return mErrorAlert (me, #noConstraints, the currentSpriteNum)
    else
    vPDList = [:]
    setaProp vPDList, #pConstrainSprite, [#comment: "Channel of the Sprite
    that provides the bounds:", \
    #format: #integer, #default: vConstraintSprites[1], #range:
    vConstraintSprites]
    setaProp vPDList, #pDraggable, [#comment: "Constrained Sprite
    draggable?", \
    #format: #boolean, #default: TRUE]
    return vPDList
    end if
    end getPropertyDescriptionList
    Christian Grass Guest

  10. #9

    Default bounding box --> finally I hope!


    If the previous thing did not work for you, I reconsidered the other
    script and made a little value change. I tested this and it works as it
    should. If for any reason it does not, I dunno what to do about this. But
    I suggest that you modify the script this way: When the user found
    something with the metal detector, he clicks one time and the detector
    does not follow anymore. If the user then clicks again, the detector
    follows as before, and so on. And here's the script to do so:

    If you just want to have it exactly the way you described it in your very
    first posting, just delete the lines I marked as modified.


    on getBehaviorDescription me
    return \
    "SPRITE TRACK MOUSE" & RETURN & RETURN & \
    "This behavior will move a sprite so that it is under the cursor. " & \
    "The sprite will appear with its registration point or center under
    the cursor's hotspot." & RETURN & RETURN & \
    "PERMITTED MEMBER TYPES:" & RETURN & \
    "Graphic members" & RETURN & RETURN & \
    "PARAMETERS:" & RETURN & \
    "* Center sprite on cursor" & RETURN & \
    "* Limited to stage area"
    end getBehaviorDescription


    on getBehaviorTooltip me
    return \
    "Makes a sprite move to follow the cursor around the stage so that the
    center of the sprite is under the cursor."
    end getBehaviorTooltip


    -- PROPERTIES --

    property pSprite -- sprite channel number
    property pStageBounds -- stage boundary values
    -- author-defined parameters
    property pCentered -- use sprite cente or loc
    property pLimited -- limit movement to stage area

    property pFollowMe -- ****** modified: inserted *********** it this is
    set true, the sprite follows the mouse
    -- if the user clicks, it toggles the value

    -- EVENT HANDLERS

    on beginSprite me
    mInitialize me
    pFollowMe = FALSE -- ****** modified: inserted **** set this TRUE if you
    want if follow from the start
    end beginSprite

    on prepareFrame me
    mUpdate me
    end prepareFrame

    -- CUSTOM HANDLERS --

    on mouseDown me -- ************************ modified: inserted handler
    ******************
    if(pFollowMe = FALSE) then --
    ************************************************** *******
    pFollowMe = TRUE --
    ************************************************** ***************
    else --
    ************************************************** *****************************
    pFollowMe = FALSE --
    ************************************************** **************
    end if --
    ************************************************** ***************************
    end mouseDown --
    ************************************************** **********************

    on mCenter vRect
    -- returns point value representing center of rectangle
    vHalfWidth = vRect.width / 2
    vHalfHeight = vRect.height / 2
    return point (vRect.left + vHalfWidth, vRect.top + vHalfHeight)
    end mCenter

    on mCenterOffset
    -- returns vector for difference between center of sprite and loc;
    -- used to ensure compatibility with text, vector, and shape sprites
    -- as well as bitmaps with offset loc values
    vCenter = mCenter (sprite (pSprite).rect)
    return vCenter - sprite (pSprite).loc
    end mCenterOffset

    on mCenteredRect vPoint, vRect
    --returns a rect centered on point vPoint
    vWidth = vRect.width
    vHeight = vRect.height
    vHalfWidth = vWidth / 2
    vHalfHeight = vHeight / 2
    vLeft = vPoint.locH - vHalfWidth
    vTop = vPoint.locV - vHalfHeight
    return rect (vLeft, vTop, vLeft + vWidth, vTop + vHeight)
    end mCenteredRect

    on mInitialize me
    -- called from beginsprite
    -- sets initial values for all conditions
    pSprite = me.spriteNum
    pStageBounds = point (the stage.rect.width, the stage.rect.height - 120)
    -- ****** inserted: "-120" --> modify to your needs
    end mInitialize

    on mStageLimit vRect
    --returns rect limited to stage area
    if vRect.left < 0 then vOffsetH = -vRect.left
    else vOffsetH = min (0, pStageBounds.locH - vRect.right)
    if vRect.top < 0 then vOffsetV = -vRect.top
    else vOffsetV = min (0, pStageBounds.locV - vRect.bottom)
    return offset (vRect, vOffsetH, vOffsetV)
    end mStageLimit

    on mUpdate me
    -- called from prepareFrame handler
    -- moves sprite to position under cursor
    if (pFollowMe = TRUE) then -- ************************** modified
    ************************
    if pCentered then
    vRect = mCenteredRect (the mouseLoc, sprite (pSprite).rect)
    else
    vRect = mCenteredRect (the mouseLoc + \
    mCenterOffset (), sprite (pSprite).rect)
    end if
    if pLimited then vRect = mStageLimit (vRect)
    sprite (pSprite).rect = vRect
    end if -- *********************************************** modified
    *************************
    end mUpdate


    -- PUBLIC METHODS --
    --Examples:
    -- on exitFrame
    -- sendSprite(whichSprite, #mSetCentered, vBool)
    -- end
    --
    --in which whichSprite is the number of the sprite for which
    --youwant to "turn on" tracking, and vBool is a boolean
    --value of either TRUE or FALSE
    --
    -- on mouseUp
    -- sendSprite(whichSprite, #mSetLimited, vBool)
    -- end
    --
    -- on mouseDown
    -- sendSprite(whichSprite, #mToggleCentered, vBool)
    -- end
    --
    -- on myCustomHandler
    -- sendSprite(whichSprite, #mToggleLimited, vBool)
    -- end myCustomHandler

    on mSetCentered me, vBool
    -- can be sent as message to sprite to determine whether
    -- sprite position is based on center or loc;
    -- if pCentered is TRUE, sprite is centered on cursor,
    -- otherwise sprite's loc is under cursor
    if not (not (vBool)) = vBool then
    pCentered = vBool
    end if
    end mSetCentered

    on mSetLimited me, vBool
    -- can be sent as message to sprite to determine whether
    -- sprite position is limited to stage rect;
    -- pLimited = TRUE means sprite won't move off stage
    if not (not (vBool)) = vBool then
    pLimited = vBool
    end if
    end mSetLimited

    on mToggleCentered me
    -- similar to mSetCentered but simply toggles boolean value
    pCentered = not pCentered
    end mToggleCentered

    on mToggleLimited me
    -- similar to mSetLimited but simply toggles boolean value
    pLimited = not pLimited
    end mToggleLimited

    -- AUTHOR-DEFINED PARAMETERS --

    on isOKToAttach (me, aSpriteType, aSpriteNum)
    case aSpriteType of
    #graphic:
    return getpos([#quickTimeMedia, #flash, #digitalvideo],
    sprite(aSpriteNum).member.type) = 0
    #script:
    return FALSE
    end case
    end isOKToAttach


    on getPropertyDescriptionList
    vPDList = [:]
    setaProp vPDList, #pCentered, [#comment: \
    "Center sprite on cursor (alternative is to use loc)", \
    #format: #boolean, #default: TRUE]
    setaProp vPDList, #pLimited, [#comment: "Limited to stage area", \
    #format: #boolean, #default: TRUE]
    return vPDList
    end getPropertyDescriptionList
    Christian Grass Guest

  11. #10

    Default bounding box --> finally I hope!


    If the previous thing did not work for you, I reconsidered the other
    script and made a little value change. I tested this and it works as it
    should. If for any reason it does not, I dunno what to do about this. But
    I suggest that you modify the script this way: When the user found
    something with the metal detector, he clicks one time and the detector
    does not follow anymore. If the user then clicks again, the detector
    follows as before, and so on. And here's the script to do so:

    If you just want to have it exactly the way you described it in your very
    first posting, just delete the lines I marked as modified.


    on getBehaviorDescription me
    return \
    "SPRITE TRACK MOUSE" & RETURN & RETURN & \
    "This behavior will move a sprite so that it is under the cursor. " & \
    "The sprite will appear with its registration point or center under
    the cursor's hotspot." & RETURN & RETURN & \
    "PERMITTED MEMBER TYPES:" & RETURN & \
    "Graphic members" & RETURN & RETURN & \
    "PARAMETERS:" & RETURN & \
    "* Center sprite on cursor" & RETURN & \
    "* Limited to stage area"
    end getBehaviorDescription


    on getBehaviorTooltip me
    return \
    "Makes a sprite move to follow the cursor around the stage so that the
    center of the sprite is under the cursor."
    end getBehaviorTooltip


    -- PROPERTIES --

    property pSprite -- sprite channel number
    property pStageBounds -- stage boundary values
    -- author-defined parameters
    property pCentered -- use sprite cente or loc
    property pLimited -- limit movement to stage area

    property pFollowMe -- ****** modified: inserted *********** it this is
    set true, the sprite follows the mouse
    -- if the user clicks, it toggles the value

    -- EVENT HANDLERS

    on beginSprite me
    mInitialize me
    pFollowMe = FALSE -- ****** modified: inserted **** set this TRUE if you
    want if follow from the start
    end beginSprite

    on prepareFrame me
    mUpdate me
    end prepareFrame

    -- CUSTOM HANDLERS --

    on mouseDown me -- ************************ modified: inserted handler
    ******************
    if(pFollowMe = FALSE) then --
    ************************************************** *******
    pFollowMe = TRUE --
    ************************************************** ***************
    else --
    ************************************************** *****************************
    pFollowMe = FALSE --
    ************************************************** **************
    end if --
    ************************************************** ***************************
    end mouseDown --
    ************************************************** **********************

    on mCenter vRect
    -- returns point value representing center of rectangle
    vHalfWidth = vRect.width / 2
    vHalfHeight = vRect.height / 2
    return point (vRect.left + vHalfWidth, vRect.top + vHalfHeight)
    end mCenter

    on mCenterOffset
    -- returns vector for difference between center of sprite and loc;
    -- used to ensure compatibility with text, vector, and shape sprites
    -- as well as bitmaps with offset loc values
    vCenter = mCenter (sprite (pSprite).rect)
    return vCenter - sprite (pSprite).loc
    end mCenterOffset

    on mCenteredRect vPoint, vRect
    --returns a rect centered on point vPoint
    vWidth = vRect.width
    vHeight = vRect.height
    vHalfWidth = vWidth / 2
    vHalfHeight = vHeight / 2
    vLeft = vPoint.locH - vHalfWidth
    vTop = vPoint.locV - vHalfHeight
    return rect (vLeft, vTop, vLeft + vWidth, vTop + vHeight)
    end mCenteredRect

    on mInitialize me
    -- called from beginsprite
    -- sets initial values for all conditions
    pSprite = me.spriteNum
    pStageBounds = point (the stage.rect.width, the stage.rect.height - 120)
    -- ****** inserted: "-120" --> modify to your needs
    end mInitialize

    on mStageLimit vRect
    --returns rect limited to stage area
    if vRect.left < 0 then vOffsetH = -vRect.left
    else vOffsetH = min (0, pStageBounds.locH - vRect.right)
    if vRect.top < 0 then vOffsetV = -vRect.top
    else vOffsetV = min (0, pStageBounds.locV - vRect.bottom)
    return offset (vRect, vOffsetH, vOffsetV)
    end mStageLimit

    on mUpdate me
    -- called from prepareFrame handler
    -- moves sprite to position under cursor
    if (pFollowMe = TRUE) then -- ************************** modified
    ************************
    if pCentered then
    vRect = mCenteredRect (the mouseLoc, sprite (pSprite).rect)
    else
    vRect = mCenteredRect (the mouseLoc + \
    mCenterOffset (), sprite (pSprite).rect)
    end if
    if pLimited then vRect = mStageLimit (vRect)
    sprite (pSprite).rect = vRect
    end if -- *********************************************** modified
    *************************
    end mUpdate


    -- PUBLIC METHODS --
    --Examples:
    -- on exitFrame
    -- sendSprite(whichSprite, #mSetCentered, vBool)
    -- end
    --
    --in which whichSprite is the number of the sprite for which
    --youwant to "turn on" tracking, and vBool is a boolean
    --value of either TRUE or FALSE
    --
    -- on mouseUp
    -- sendSprite(whichSprite, #mSetLimited, vBool)
    -- end
    --
    -- on mouseDown
    -- sendSprite(whichSprite, #mToggleCentered, vBool)
    -- end
    --
    -- on myCustomHandler
    -- sendSprite(whichSprite, #mToggleLimited, vBool)
    -- end myCustomHandler

    on mSetCentered me, vBool
    -- can be sent as message to sprite to determine whether
    -- sprite position is based on center or loc;
    -- if pCentered is TRUE, sprite is centered on cursor,
    -- otherwise sprite's loc is under cursor
    if not (not (vBool)) = vBool then
    pCentered = vBool
    end if
    end mSetCentered

    on mSetLimited me, vBool
    -- can be sent as message to sprite to determine whether
    -- sprite position is limited to stage rect;
    -- pLimited = TRUE means sprite won't move off stage
    if not (not (vBool)) = vBool then
    pLimited = vBool
    end if
    end mSetLimited

    on mToggleCentered me
    -- similar to mSetCentered but simply toggles boolean value
    pCentered = not pCentered
    end mToggleCentered

    on mToggleLimited me
    -- similar to mSetLimited but simply toggles boolean value
    pLimited = not pLimited
    end mToggleLimited

    -- AUTHOR-DEFINED PARAMETERS --

    on isOKToAttach (me, aSpriteType, aSpriteNum)
    case aSpriteType of
    #graphic:
    return getpos([#quickTimeMedia, #flash, #digitalvideo],
    sprite(aSpriteNum).member.type) = 0
    #script:
    return FALSE
    end case
    end isOKToAttach


    on getPropertyDescriptionList
    vPDList = [:]
    setaProp vPDList, #pCentered, [#comment: \
    "Center sprite on cursor (alternative is to use loc)", \
    #format: #boolean, #default: TRUE]
    setaProp vPDList, #pLimited, [#comment: "Limited to stage area", \
    #format: #boolean, #default: TRUE]
    return vPDList
    end getPropertyDescriptionList
    Christian Grass Guest

  12. #11

    Default Re: bounding box? -- finally I hope!

    Sorry, my message went not out as a reply. But here it is again, now
    hopefully at the right posting:
    ------------------------------------------------------------------------------------------------

    If the previous thing did not work for you, I reconsidered the other
    script and made a little value change. I tested this and it works as it
    should. If for any reason it does not, I dunno what to do about this. But
    I suggest that you modify the script this way: When the user found
    something with the metal detector, he clicks one time and the detector
    does not follow anymore. If the user then clicks again, the detector
    follows as before, and so on. And here's the script to do so:

    If you just want to have it exactly the way you described it in your very
    first posting, just delete the lines I marked as modified.


    on getBehaviorDescription me
    return \
    "SPRITE TRACK MOUSE" & RETURN & RETURN & \
    "This behavior will move a sprite so that it is under the cursor. " & \
    "The sprite will appear with its registration point or center under
    the cursor's hotspot." & RETURN & RETURN & \
    "PERMITTED MEMBER TYPES:" & RETURN & \
    "Graphic members" & RETURN & RETURN & \
    "PARAMETERS:" & RETURN & \
    "* Center sprite on cursor" & RETURN & \
    "* Limited to stage area"
    end getBehaviorDescription


    on getBehaviorTooltip me
    return \
    "Makes a sprite move to follow the cursor around the stage so that the
    center of the sprite is under the cursor."
    end getBehaviorTooltip


    -- PROPERTIES --

    property pSprite -- sprite channel number
    property pStageBounds -- stage boundary values
    -- author-defined parameters
    property pCentered -- use sprite cente or loc
    property pLimited -- limit movement to stage area

    property pFollowMe -- ****** modified: inserted *********** it this is
    set true, the sprite follows the mouse
    -- if the user clicks, it toggles the value

    -- EVENT HANDLERS

    on beginSprite me
    mInitialize me
    pFollowMe = FALSE -- ****** modified: inserted **** set this TRUE if you
    want if follow from the start
    end beginSprite

    on prepareFrame me
    mUpdate me
    end prepareFrame

    -- CUSTOM HANDLERS --

    on mouseDown me -- ************************ modified: inserted handler
    ******************
    if(pFollowMe = FALSE) then --
    ************************************************** *******
    pFollowMe = TRUE --
    ************************************************** ***************
    else --
    ************************************************** *****************************
    pFollowMe = FALSE --
    ************************************************** **************
    end if --
    ************************************************** ***************************
    end mouseDown --
    ************************************************** **********************

    on mCenter vRect
    -- returns point value representing center of rectangle
    vHalfWidth = vRect.width / 2
    vHalfHeight = vRect.height / 2
    return point (vRect.left + vHalfWidth, vRect.top + vHalfHeight)
    end mCenter

    on mCenterOffset
    -- returns vector for difference between center of sprite and loc;
    -- used to ensure compatibility with text, vector, and shape sprites
    -- as well as bitmaps with offset loc values
    vCenter = mCenter (sprite (pSprite).rect)
    return vCenter - sprite (pSprite).loc
    end mCenterOffset

    on mCenteredRect vPoint, vRect
    --returns a rect centered on point vPoint
    vWidth = vRect.width
    vHeight = vRect.height
    vHalfWidth = vWidth / 2
    vHalfHeight = vHeight / 2
    vLeft = vPoint.locH - vHalfWidth
    vTop = vPoint.locV - vHalfHeight
    return rect (vLeft, vTop, vLeft + vWidth, vTop + vHeight)
    end mCenteredRect

    on mInitialize me
    -- called from beginsprite
    -- sets initial values for all conditions
    pSprite = me.spriteNum
    pStageBounds = point (the stage.rect.width, the stage.rect.height - 120)
    -- ****** inserted: "-120" --> modify to your needs
    end mInitialize

    on mStageLimit vRect
    --returns rect limited to stage area
    if vRect.left < 0 then vOffsetH = -vRect.left
    else vOffsetH = min (0, pStageBounds.locH - vRect.right)
    if vRect.top < 0 then vOffsetV = -vRect.top
    else vOffsetV = min (0, pStageBounds.locV - vRect.bottom)
    return offset (vRect, vOffsetH, vOffsetV)
    end mStageLimit

    on mUpdate me
    -- called from prepareFrame handler
    -- moves sprite to position under cursor
    if (pFollowMe = TRUE) then -- ************************** modified
    ************************
    if pCentered then
    vRect = mCenteredRect (the mouseLoc, sprite (pSprite).rect)
    else
    vRect = mCenteredRect (the mouseLoc + \
    mCenterOffset (), sprite (pSprite).rect)
    end if
    if pLimited then vRect = mStageLimit (vRect)
    sprite (pSprite).rect = vRect
    end if -- *********************************************** modified
    *************************
    end mUpdate


    -- PUBLIC METHODS --
    --Examples:
    -- on exitFrame
    -- sendSprite(whichSprite, #mSetCentered, vBool)
    -- end
    --
    --in which whichSprite is the number of the sprite for which
    --youwant to "turn on" tracking, and vBool is a boolean
    --value of either TRUE or FALSE
    --
    -- on mouseUp
    -- sendSprite(whichSprite, #mSetLimited, vBool)
    -- end
    --
    -- on mouseDown
    -- sendSprite(whichSprite, #mToggleCentered, vBool)
    -- end
    --
    -- on myCustomHandler
    -- sendSprite(whichSprite, #mToggleLimited, vBool)
    -- end myCustomHandler

    on mSetCentered me, vBool
    -- can be sent as message to sprite to determine whether
    -- sprite position is based on center or loc;
    -- if pCentered is TRUE, sprite is centered on cursor,
    -- otherwise sprite's loc is under cursor
    if not (not (vBool)) = vBool then
    pCentered = vBool
    end if
    end mSetCentered

    on mSetLimited me, vBool
    -- can be sent as message to sprite to determine whether
    -- sprite position is limited to stage rect;
    -- pLimited = TRUE means sprite won't move off stage
    if not (not (vBool)) = vBool then
    pLimited = vBool
    end if
    end mSetLimited

    on mToggleCentered me
    -- similar to mSetCentered but simply toggles boolean value
    pCentered = not pCentered
    end mToggleCentered

    on mToggleLimited me
    -- similar to mSetLimited but simply toggles boolean value
    pLimited = not pLimited
    end mToggleLimited

    -- AUTHOR-DEFINED PARAMETERS --

    on isOKToAttach (me, aSpriteType, aSpriteNum)
    case aSpriteType of
    #graphic:
    return getpos([#quickTimeMedia, #flash, #digitalvideo],
    sprite(aSpriteNum).member.type) = 0
    #script:
    return FALSE
    end case
    end isOKToAttach


    on getPropertyDescriptionList
    vPDList = [:]
    setaProp vPDList, #pCentered, [#comment: \
    "Center sprite on cursor (alternative is to use loc)", \
    #format: #boolean, #default: TRUE]
    setaProp vPDList, #pLimited, [#comment: "Limited to stage area", \
    #format: #boolean, #default: TRUE]
    return vPDList
    end getPropertyDescriptionList
    Christian Grass Guest

  13. #12

    Default Re: bounding box? -- finally I hope!

    Sorry, my message went not out as a reply. But here it is again, now
    hopefully at the right posting:
    ------------------------------------------------------------------------------------------------

    If the previous thing did not work for you, I reconsidered the other
    script and made a little value change. I tested this and it works as it
    should. If for any reason it does not, I dunno what to do about this. But
    I suggest that you modify the script this way: When the user found
    something with the metal detector, he clicks one time and the detector
    does not follow anymore. If the user then clicks again, the detector
    follows as before, and so on. And here's the script to do so:

    If you just want to have it exactly the way you described it in your very
    first posting, just delete the lines I marked as modified.


    on getBehaviorDescription me
    return \
    "SPRITE TRACK MOUSE" & RETURN & RETURN & \
    "This behavior will move a sprite so that it is under the cursor. " & \
    "The sprite will appear with its registration point or center under
    the cursor's hotspot." & RETURN & RETURN & \
    "PERMITTED MEMBER TYPES:" & RETURN & \
    "Graphic members" & RETURN & RETURN & \
    "PARAMETERS:" & RETURN & \
    "* Center sprite on cursor" & RETURN & \
    "* Limited to stage area"
    end getBehaviorDescription


    on getBehaviorTooltip me
    return \
    "Makes a sprite move to follow the cursor around the stage so that the
    center of the sprite is under the cursor."
    end getBehaviorTooltip


    -- PROPERTIES --

    property pSprite -- sprite channel number
    property pStageBounds -- stage boundary values
    -- author-defined parameters
    property pCentered -- use sprite cente or loc
    property pLimited -- limit movement to stage area

    property pFollowMe -- ****** modified: inserted *********** it this is
    set true, the sprite follows the mouse
    -- if the user clicks, it toggles the value

    -- EVENT HANDLERS

    on beginSprite me
    mInitialize me
    pFollowMe = FALSE -- ****** modified: inserted **** set this TRUE if you
    want if follow from the start
    end beginSprite

    on prepareFrame me
    mUpdate me
    end prepareFrame

    -- CUSTOM HANDLERS --

    on mouseDown me -- ************************ modified: inserted handler
    ******************
    if(pFollowMe = FALSE) then --
    ************************************************** *******
    pFollowMe = TRUE --
    ************************************************** ***************
    else --
    ************************************************** *****************************
    pFollowMe = FALSE --
    ************************************************** **************
    end if --
    ************************************************** ***************************
    end mouseDown --
    ************************************************** **********************

    on mCenter vRect
    -- returns point value representing center of rectangle
    vHalfWidth = vRect.width / 2
    vHalfHeight = vRect.height / 2
    return point (vRect.left + vHalfWidth, vRect.top + vHalfHeight)
    end mCenter

    on mCenterOffset
    -- returns vector for difference between center of sprite and loc;
    -- used to ensure compatibility with text, vector, and shape sprites
    -- as well as bitmaps with offset loc values
    vCenter = mCenter (sprite (pSprite).rect)
    return vCenter - sprite (pSprite).loc
    end mCenterOffset

    on mCenteredRect vPoint, vRect
    --returns a rect centered on point vPoint
    vWidth = vRect.width
    vHeight = vRect.height
    vHalfWidth = vWidth / 2
    vHalfHeight = vHeight / 2
    vLeft = vPoint.locH - vHalfWidth
    vTop = vPoint.locV - vHalfHeight
    return rect (vLeft, vTop, vLeft + vWidth, vTop + vHeight)
    end mCenteredRect

    on mInitialize me
    -- called from beginsprite
    -- sets initial values for all conditions
    pSprite = me.spriteNum
    pStageBounds = point (the stage.rect.width, the stage.rect.height - 120)
    -- ****** inserted: "-120" --> modify to your needs
    end mInitialize

    on mStageLimit vRect
    --returns rect limited to stage area
    if vRect.left < 0 then vOffsetH = -vRect.left
    else vOffsetH = min (0, pStageBounds.locH - vRect.right)
    if vRect.top < 0 then vOffsetV = -vRect.top
    else vOffsetV = min (0, pStageBounds.locV - vRect.bottom)
    return offset (vRect, vOffsetH, vOffsetV)
    end mStageLimit

    on mUpdate me
    -- called from prepareFrame handler
    -- moves sprite to position under cursor
    if (pFollowMe = TRUE) then -- ************************** modified
    ************************
    if pCentered then
    vRect = mCenteredRect (the mouseLoc, sprite (pSprite).rect)
    else
    vRect = mCenteredRect (the mouseLoc + \
    mCenterOffset (), sprite (pSprite).rect)
    end if
    if pLimited then vRect = mStageLimit (vRect)
    sprite (pSprite).rect = vRect
    end if -- *********************************************** modified
    *************************
    end mUpdate


    -- PUBLIC METHODS --
    --Examples:
    -- on exitFrame
    -- sendSprite(whichSprite, #mSetCentered, vBool)
    -- end
    --
    --in which whichSprite is the number of the sprite for which
    --youwant to "turn on" tracking, and vBool is a boolean
    --value of either TRUE or FALSE
    --
    -- on mouseUp
    -- sendSprite(whichSprite, #mSetLimited, vBool)
    -- end
    --
    -- on mouseDown
    -- sendSprite(whichSprite, #mToggleCentered, vBool)
    -- end
    --
    -- on myCustomHandler
    -- sendSprite(whichSprite, #mToggleLimited, vBool)
    -- end myCustomHandler

    on mSetCentered me, vBool
    -- can be sent as message to sprite to determine whether
    -- sprite position is based on center or loc;
    -- if pCentered is TRUE, sprite is centered on cursor,
    -- otherwise sprite's loc is under cursor
    if not (not (vBool)) = vBool then
    pCentered = vBool
    end if
    end mSetCentered

    on mSetLimited me, vBool
    -- can be sent as message to sprite to determine whether
    -- sprite position is limited to stage rect;
    -- pLimited = TRUE means sprite won't move off stage
    if not (not (vBool)) = vBool then
    pLimited = vBool
    end if
    end mSetLimited

    on mToggleCentered me
    -- similar to mSetCentered but simply toggles boolean value
    pCentered = not pCentered
    end mToggleCentered

    on mToggleLimited me
    -- similar to mSetLimited but simply toggles boolean value
    pLimited = not pLimited
    end mToggleLimited

    -- AUTHOR-DEFINED PARAMETERS --

    on isOKToAttach (me, aSpriteType, aSpriteNum)
    case aSpriteType of
    #graphic:
    return getpos([#quickTimeMedia, #flash, #digitalvideo],
    sprite(aSpriteNum).member.type) = 0
    #script:
    return FALSE
    end case
    end isOKToAttach


    on getPropertyDescriptionList
    vPDList = [:]
    setaProp vPDList, #pCentered, [#comment: \
    "Center sprite on cursor (alternative is to use loc)", \
    #format: #boolean, #default: TRUE]
    setaProp vPDList, #pLimited, [#comment: "Limited to stage area", \
    #format: #boolean, #default: TRUE]
    return vPDList
    end getPropertyDescriptionList
    Christian Grass Guest

  14. #13

    Default Re: bounding box? -- finally I hope!

    "Christian Grass" <someone@something.net> wrote in message
    news:oprzubzlrvi5yru5@forums.macromedia.com...
    > Sorry, my message went not out as a reply. But here it is again, now
    > hopefully at the right posting:
    Um, how many times do you need to post the same message, exactly? I suggest
    you check your newsreader is set up properly in macromedia.test.

    - Robert



    Robert Tweed Guest

  15. #14

    Default Re: bounding box? -- finally I hope!

    thanks Christian. i'll try it this afternoon/evening and will let you know.


    adams2003 webforumsuser@macromedia.com Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139