Page 1 of 1

Btn can't find fields, etc on same card/stack

Posted: Mon Oct 12, 2009 3:34 pm
by gyroscope
Hi, I've a bit of a frustrating prob which has occurred, and I can't work out why.

I've a main stack with an onOpencard script including:

Code: Select all

lock screen
open stack "PROCESSES A" 
hide stack "PROCESSES A"
unlock screen
send "mouseUp" to btn "startupmain" on stack "PROCESSES A"
All well and good, it reaches and activates the button, as always.

Script in button "startupmain" including:

Code: Select all

repeat with gClap=1 to 48
      put empty into field ("w"&gClap)
      set the backgroundColor of field ("w"&gClap) to white      
   end repeat
There's an error thrown here: it can't find field "w1" etc., all of a sudden (there wasn't a problem before).

The only way around this, of course, is to append "on card 2 of stack "PROCESSES A" to each command. This is a pain as there's a fair bit of code in the button; and I'm a bit miffed that, apart from making the script a bit denser and more difficult to read, I shouldn't have to do this.

I hasten to add that if btn "startupmain" is clicked directly, everything is executed fine.

So does anyone know please, why that when the mouseUp is sent to the button from the main stack, and the button executes, it can't find the fields/buttons, etc on it's shared card/stack? (suddenly...) Any help appreciated here as this has been driving me a bit bonkers to solve...

:(

Posted: Mon Oct 12, 2009 4:02 pm
by Klaus
Hi gyroscope,

if Rev loses "connection" this can most of the time be "cured" by setting the "defaultstack" first before the handler begins:

Code: Select all

on mouseup
  set the defaultstack to "PROCESSES A" 
  ## or whereever the "missing" fields are located...
   repeat with ...
   ...
end mouseup
Best

Klaus

Posted: Mon Oct 12, 2009 6:10 pm
by gyroscope
Hi Klaus

Thank you for your help. Unfortunately it doesn't work in my situation (although reading "defaultStack" in the Dictionary I see that it should).

I've tried a few more things to no avail. I guess I've really tangled it up somehow. I'm going to start from scratch, copying all relevant stuff across to a fresh set of stacks; it'll take a while but I think it's worth it, especially as I'll be using a lot of send mouseUps throughout.

:)

Posted: Mon Oct 12, 2009 9:08 pm
by chris9610
gyroscope:

Code: Select all

repeat with gClap=1 to 48
      put empty into field ("w"&gClap)
      set the backgroundColor of field ("w"&gClap) to white     
   end repeat
You are sending to mouseup so the script should be:

Code: Select all

on mouseup
repeat with gClap=1 to 48
      put empty into field ("w"&gClap)
      set the backgroundColor of field ("w"&gClap) to white     
   end repeat
end mouseup
Best guess here .

Posted: Mon Oct 12, 2009 9:25 pm
by Mark
Dear gyroscope,

My guess is that the current card of stack PROCESSES A is card 1 rather than card 2. Running scripts expect objects to be on the current card, if the card or stack isn't made explicit. Setting the defaultstack won't solve this. You have to go invisible to card 2 of stack PROCESSES A to solve the problem.

Best,

Mark

Posted: Mon Oct 12, 2009 9:44 pm
by gyroscope
Hi Chris,

the code is in a mouseUp handler, I took it as read that that was the case, but thanks for the info!

Hi Mark

Spot on, that's the one, thank you very much. That has solved hours of head-scratching and experiments!

:) :)

Posted: Mon Oct 12, 2009 10:46 pm
by chris9610
I guess I misunderstood the issue.

But here are my thoughts.

Cards and fields, buttons and other objects can be copied and names can be identical on different cards so it is up to you to address the proper object with which you want to work with at any instance.

With mighty powers comes mighty responsibility. I think the advantages out weight the dis-advantages. Based on my experience which is minor compared with others.

Can you imagine always having unique names for every field or button in a large application?

I hope this helps.

Posted: Tue Oct 13, 2009 2:03 pm
by gyroscope
Hi Chris
Cards and fields, buttons and other objects can be copied and names can be identical on different cards so it is up to you to address the proper object with which you want to work with at any instance.
I'm aware of the good principal to name things differently, thanks for reminding me.

My prob concerned sending mouseUps to buttons on other stacks, which Mark gave the solution to. It was "half-a-d'oh" moment for me!

Best regards

:)