before vs on in behavior scripts - red herring alert!

Devin Asay devin_asay at byu.edu
Thu Mar 20 11:09:15 EDT 2014


On Mar 18, 2014, at 5:33 PM, Devin Asay <devin_asay at byu.edu> wrote:

> All,
> 
> If a button has a behavior attached to it, and the behavior script has a 'before mouseUp' handler, can the behavior script also have a 'on mouseUp' handler?
> 
> I could swear the answer was yes; I thought I had done that before, but now when I try it, it doesn't work. (In LC 6.5.x. and 6.6.0RC2). Instead I have to put the 'in mouseUp' in the button's script.
> 
> Of course I might be completely missing the point of 'before' and 'after' handlers. Wouldn't be the first time.

I think I figured out the problem, and actually my initial post was a red herring. There is still a little mystery. I had assigned behaviors to several buttons in my main project stack; the button containing the behavior script is in a library stack. So far so good. Everything worked the way it was supposed to. But later I came back into the project and added an 'on mouseUp' handler to the behavior script. However, the new ON handler never fired. (In fact, none of the handlers in the behavior script were being fired, and I couldn't invoke the debugger in the behavior script after placing breakpoints in it.) After a little tinkering I discovered that if I reassigned the behavior to just one the buttons that the handlers in the behavior worked again, for ALL of the buttons. 

The red herring part happened because the BEFORE and AFTER handlers were being used to set up and down icon states in the buttons using that behavior. The icon states were always working properly when the ON mouseUp handler would not. Later I discovered that *someone* (I blame the code kabouters*) had gone in and assigned icon states to the buttons using the behaviors, rendering the BEFORE and AFTER handlers redundant. So I was left thinking only some of the behavior handlers were working, when in fact none of them were.

So it appears that each time I launch the project I have to reassign the behavior to the buttons. This only seems to happen for behaviors stored in library stacks. I have seen a similar problem with objects that were assigned a background pattern stored in a library stack. In that instance I finally had to add a line of code in my preOpenStack handler to reassign the bg pattern. Now it appears I'll have to do the same for these behaviors. But it doesn't seem right. Shouldn't I expect that buttons with behaviors contained in a library stack will always find those behaviors once the stack is reopened and the library stack has been start-using'ed? Or am I misunderstanding something (again)? Or maybe I stumbled upon a bug? Anyone know?

Devin

Devin Asay
Learn to code with LiveCode University
http://university.livecode.com



* kabouters = gnomes. In this case the Dutch have the far better word.






More information about the use-livecode mailing list