how to execute button on card from button on previous card

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
mikemc
Posts: 60
Joined: Sun May 10, 2015 5:42 pm

how to execute button on card from button on previous card

Post by mikemc » Sun May 17, 2015 6:17 pm

I have 7 cards I would like to execute a button on card1 have it run its code which would
include code to executing a button and card2 and card3

Klaus
Posts: 14267
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: how to execute button on card from button on previous ca

Post by Klaus » Sun May 17, 2015 6:22 pm

Hi Mike,

this should do:
..
send "mouseup" to btn "your btn here" of cd "your target card here"
...
:D


Best

Klaus

SparkOut
Posts: 2961
Joined: Sun Sep 23, 2007 4:58 pm

Re: how to execute button on card from button on previous ca

Post by SparkOut » Sun May 17, 2015 6:31 pm

more elegant still is to have the buttons simply call a handler that is stored further up the message path (eg stack script).

So your button could have the script

Code: Select all

on mouseUp
   doMyEvents
end mouseUp
and the stack script would include the handler

Code: Select all

on doMyEvents
  --do the things you want
  answer "I'm working on the tasks"
end doMyEvents
You can then use the same handler from anywhere in the stack, whichever card you are on when you want to call it. Sending messages to objects is great and powerful, but it is preferable to work with the natural message path when you can.

When you have understood a bit more, you should also investigate behavior scripts.

mikemc
Posts: 60
Joined: Sun May 10, 2015 5:42 pm

Re: how to execute button on card from button on previous ca

Post by mikemc » Sun May 17, 2015 6:56 pm

Thanks but the problem I'm running into is when the button is executed on the second card
its code uses fields in the second card and I'm getting no such object when it tries to use
these fields on the second card i guess because i'm still on the first card any answers?

SparkOut
Posts: 2961
Joined: Sun Sep 23, 2007 4:58 pm

Re: how to execute button on card from button on previous ca

Post by SparkOut » Sun May 17, 2015 7:53 pm

same answer as for the other thread you made :)

refer to the fields with the descriptor of the card they are on: field "fieldName" of card "cardName".
But as you get more experienced you will find less need to do this sort of thing.

mikemc
Posts: 60
Joined: Sun May 10, 2015 5:42 pm

Re: how to execute button on card from button on previous ca

Post by mikemc » Mon May 18, 2015 3:03 pm

thanks it works I will just have to finish changing the code for two buttons by adding the card
name to every field. This is just my first app so should be good for now :D

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: how to execute button on card from button on previous ca

Post by Simon » Mon May 18, 2015 6:06 pm

Hi mikemc,
You can use
fld "myField" of this card
But also you can call the field from it's layer level
fld 1 of this cd

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

SparkOut
Posts: 2961
Joined: Sun Sep 23, 2007 4:58 pm

Re: how to execute button on card from button on previous ca

Post by SparkOut » Mon May 18, 2015 6:25 pm

This, me, the target, the owner will all be useful in days to come. But today, "this card" is not going to help, when referring to a field on a card other than this. So longhand addition of the card name to identify where the field is, is the order for now.
Success with this app/Scripting Conferences, object resolution, message path, behaviors, would be a natural progression.

Post Reply