1

I have a livecode project with five cards. First card has one label "label1", Second card has two labels "Greeting" and "Word", Third card has a button "button1", Fourth card has a textbox "text1", and the fifth card has a label "HelloWord".

My goal is to display "Hello" to all controls mentioned above.

I have this code in every card

Card 1

on openCard
put "Hello" to field "label1"
end openCard

Card 2

on openCard
put "Hello" to field "Greeting"
put "Hello" to field "Word"
end openCard

Card 3

on openCard
put "Hello" to button "button1"
end openCard

Card 4

on openCard
put "Hello" to field "text1"
end openCard

Card 5

on openCard
put "Hello" to field "HelloWord"
end openCard

Mainstack

on openStack
go to card "card1"
go to card "card2"
go to card "card3"
go to card "card4"
go to card "card5"
end openStack

These codes are working.

But I want the program to execute those on openCard scripts in every card on startup without going to another card.

I tried to execute those scripts in on openStack (without go to card scripts) but I got an error. The error says "can't find handler".

How can I do that?

Mai
  • 363
  • 3
  • 16

1 Answers1

0

You could move the code from the openCard handler to a different handler, e.g. initializeCardand call that handler from both the openCard and the openStack handlers. However, if a card executes a script and refers to objects on that card, you may get the object not found handler. Therefore, you need to refer to objects on the card explicitly, using of me or of card <card name>.

on openStack
  repeat with x = 1 to number of cards
    send "initializeCard`to card x
  end repeat
end openStack

// example for card 2
on initializeCard
  put "Hello" to field "Greeting" of me
  put "Hello" to field "Word" of me
end initializeCard

Your script that goes to all cards is also a good solution, but you might want to lock the screen, to make it look like you're not switching cards:

on openStack
  lock screen
  go cd "card1"
  go cd "card2"
  go cd "card3"
  go cd "card4"
  go cd "card5"
  go cd "card1"
  unlock screen
end openStack
Mark
  • 2,380
  • 11
  • 29
  • 49
  • Locking the screen could be effective in preparing the application such as loading screen. Thanks for your help. – Mai Jan 01 '15 at 05:53