User Guide

447
This statement displays in the Message window the beginning position of the string “Micro
within the string “Macromedia”:
put offset("Micro", "Macromedia")
The result is 0, because “Macromedia” doesnt contain the string “Micro”.
This handler finds all instances of the string represented by
stringToFind within the string
represented by
input and replaces them with the string represented by stringToInsert:
on SearchAndReplace input, stringToFind, stringToInsert
output = ""
findLen = stringToFind.length - 1
repeat while input contains stringToFind
currOffset = offset(stringToFind, input)
output = output & input.char [1..currOffset]
delete the last char of output
output = output & stringToInsert
delete input.char [1.. (currOffset + findLen)]
end repeat
set output = output & input
return output
end
See also
chars(), length(), contains, starts
offset() (rectangle function)
Syntax
rectangle.offset(horizontalChange, verticalChange)
offset (rectangle, horizontalChange, verticalChange)
Description
Function; yields a rectangle that is offset from the rectangle specified by rectangle. The
horizontal offset is the value specified by
horizontalChange; the vertical offset is the value
specified by
verticalChange.
When horizontalChange is greater than 0, the offset is toward the right of the Stage; when
horizontalChange is less than 0, the offset is toward the left of the Stage.
When verticalChange is greater than 0, the offset is toward the top of the Stage; when
verticalChange is less than 0, the offset is toward the bottom of the Stage.
The values for
verticalChange and horizontalChange are in pixels.
Example
This handler moves sprite 1 five pixels to the right and five pixels down:
on diagonalMove
newRect=sprite(1).rect.offset(5, 5)
sprite(1).rect=newRect
end