livecode.com
  • Home
  • Download
  • Developers
  • Academy
  • Community
  • Store
  • Support
  • About
LiveCode Lessons » Getting Started with LiveCode Development » Using Buttons and Default Buttons

Topics

  • Before you start 2
    • The Structure of a LiveCode Application
    • The LiveCode Message Path
  • Basic Concepts 7
    • Adding Objects to a Stack
    • Navigating Around a Stack
    • LiveCode Properties
    • Scripting a Button
    • Communicating with the User
    • Working With Text
    • Reading and Writing to File
  • LiveCode Objects 8
    • Using Buttons and Default Buttons
    • Using Fields
    • Using Radio Buttons
    • Using Option Menus
    • Text in the Tab Panel
    • Using Progress Bars
    • Using Images
    • Using Players
  • Building a User Interface 2
    • Using Button Icons and Background Images
    • Using Visual Effects
  • Building a Standalone Application 1
    • Building Standalone Applications
  • Your first LiveCode Application 1
    • Hello World!
  • The next step - Creating a 3-5-7 Game 3
    • Game 3-5-7 - A Simple Interface
    • Game 3-5-7 - Basic Functionality
    • Game 3-5-7 - Game Logic

Last Updated

Oct 12, 2011

Download Lesson PDF

Other Resources

  • Getting Started with LiveCode

  • Get Up and Running with LiveCode
  • Getting Started with LiveCode Development
  • LiveCode Concepts

  • Features, concepts and aspects of LiveCode
  • LiveCode Lessons

  • How To - Step-By-Step Guides To Tasks In LiveCode
  • How To - LiveCode Server Tasks
  • How To - LiveCode Mobile Tasks
  • How To - LiveCode Sample Scripts
  • How to - LiveCode Marketplace Products
  • How to Purchase and License LiveCode
  • Tutorials

  • Creating a Video Library Application
  • Data Grid

  • LiveCode Data Grid
  • Data Grid Tips & Tricks
  • Converting the Stock Program

Comments

2 for this lesson

  • Prev: Reading and Writing to File
  • Next: Using Fields

Using Buttons and Default Buttons

This tutorial introduces the concepts of buttons and default buttons to you.

Introduction

Buttons are fundamental entities that allow you to interact with devices, for example with mechanical buttons on a keyboard or a remote control, or graphical buttons on a touch sensitive computer display. This tutorial looks at how to use buttons to interact with a LiveCode application.

Creating the Buttons

Zoom

Start LiveCode and open a stack window by selecting New Mainstack from the File Menu. Then drag and drop a Push Button (1), a Default Button (2) and a Rectangle Button (3) onto the card. You can space these buttons out as you like. Then rename the buttons from left to right "Button 1", "Button 2" and "Button 3". You can rename the buttons by right clicking on a button and selecting Property Inspector (4). This opens a new dialog box. Make sure that Basic Properties is selected from the drop down list of the new dialog box. Then change the name in the "Name" field (5). You can also view the types of buttons that are available to you in the style drop down list (6). For this example it is not necessary to select any other button types from the drop down list.

Adding the Code

Once you have created the button controls on the card and renamed them, you can add code to each button. Right click on each button and select Edit Script, this opens the script editor with two default lines of code:

on mouseUp

end mouseUp

mouseUp is a handler that is called each time a button receives a mouse event. You can populate the area between on mouseUp and end mouseUp, in order to provide functionality to the buttons.

Add the following code to "Button 1":

on mouseUp
    answer "Square Button" with "Okay"
end mouseUp

Add the following code to "Button 2":

on mouseUp
    answer "Default Button" with "Okay"
end mouseUp

Add the following code to "Button 3":

on mouseUp
    answer "Rounded Button" with "Okay"
end mouseUp

Buttons in Action

Zoom

All of the button that were created in this tutorial can be selected with the mouse, but "Button 2" also acts as a default button, allowing it to be selected using the Enter or Return keys on a keyboard. This is a useful feature that is often used in installers or applications that lead you through a sequence of steps that have a default option. In this case the user would not have to select a particular button each time a new step was presented but could rapidly run through all pages by pressing the Enter or Return key for each screen or step. The LiveCode application you created operates in a similar way. Try pressing the Enter or Return key and see how "Button 2" is pressed, a dialog appears and "Okay" is pressed. This loop of pressing "Button 2" a dialog appearing and pressing "Okay" can continue indefinitely.

Further Reading

If you are interested in more information on using buttons, then have a look at tutorial Using Radio Buttons.

  • Prev: Reading and Writing to File
  • Next: Using Fields

Comments (2)

Chris Friday Mar 16 at 03:49 PM

How do you add an image to a button? (regular)

Hanson Schmidt-Cornelius Monday Mar 19 at 02:56 AM

Hi Chris,

there is a tutorial in the LiveCode Resource Centre that answers this question and runs you through the required steps.

You can access the tutorial by opening LiveCode and selecting: "Help ->
Resource Centre".
This opens a new window. On the left hand side of the new window, navigate to: "Tutorials -> Graphical Interface -> Skinning"

Kind Regards,

Hanson

Add your comment

E-Mail me when someone replies to this comment
Brought to you by RunRev Ltd, Registered in Scotland, No. SC200728