heya kaveh,
Interesting problem, but seems like you have a communication breakdown. I am curious about something though, it seems like you are trying to re-invent something the field does all on its own by default, i.e. when you type in a field, the scroll automatically drops down when the text is changed. Not a problem, but why?
First, what Klaus is saying is absolutely right, if you want a variable to work across 2 separate handlers, the easiest way would be to put it outside of the handlers and into the script at an appropriate location.
The second thing I would suggest is putting your relevant (to the problem) code into one code block instead of the three you have in that first post, to make it easier to follow (see below).
The last thing I would suggest is that since you list a handler to correct the scroll, you not send things back to themselves but instead just call the handler. As a side note, I would also not name your fields with reserved words, like 'text'! Also, tScroll
≠ sScroll
Here is your code as copied from the first post, but with 'tScroll' listed as script local variable [ I put in psuedo handlers since they weren't included for illustration only]-
Code: Select all
local tScroll
on textChanged
put the vscroll of fld "text" to tScroll // field named "text" ?!? Please change this!
... [modify text]
set the vscroll of fld "text" to tScroll
end textChanged
on enterInField
put the vscroll of fld "text" to tScroll
... [modify text]
send correct_scroll to me in 10 ticks
...
end enterInField
on correct_scroll
set the vscroll of fld "text" to tScroll
end correct_scroll
You have a handler, 'correct_scroll', but you don't call it like it would make sense to use it, unless you really need that 10 tick delay. If you really want to avoid using a script level variable, I would just call the handler each time (of course, you'll have to beef that handler up a bit more).
An Example of this would be like -
Code: Select all
// using a handler only to correct the scroll...
on mouseDown
// set the scrollbar to the top of the field...
set the vscroll of fld "myField" to 1
end mouseDown
on mouseUp
// call the handler...
correct_scroll
end mouseUp
on correct_scroll
// set the vscroll to the bottom of the field...
set the vscroll of fld "myField" to the formattedHeight of field "myField"
end correct_scroll
The above code produces this effect -
- Mouse down...
- Selection_001.png (7.21 KiB) Viewed 3683 times
- Mouse up!
- Selection_002.png (6.11 KiB) Viewed 3683 times
Now, locating the variable in a handler means that as each handler finishes, the variable becomes empty. You *could* do something like -
Code: Select all
on mouseUp
local tScroll // local inside of handler...
put the vscroll of fld "text" to tScroll
end mouseUp
which will allow you to use it where ever else you include the line 'local tScroll' within the script level, but that is far less efficient than doing it the way I modified your code up there in the first block, and even that is far less efficient than just making the handler 'correct_scroll' do the work.
I'd really encourage you to stay away from global variables if you can possibly avoid them at this stage, they can make life way too interesting in ways you don't need it to be.
Hope that helps
*Edited to make better sense and correct error sentences