Tuesday, November 28, 2017

My 1st CODE APP - Button Untitled Project - App Lab

Untitled Project - App Lab:



button

Category:UI Controls
Creates a button on the screen displaying the text provided and referenced by the given id at default location (0,0).
Many apps use buttons to allow the user to initiate some app action. An event handler must be created for each type of user interaction with the button using onEvent() and the id.

Examples

1
// Create a "Click Me" button.
2
button("id", "Click Me!");

Example: Simple Turtle Control 1

Move the turtle forward on every click of the button.
1
// Move the turtle forward on every click of the button.
2
button("forward", "Move Forward");
3
onEvent("forward", "click", function(event) {
4
  moveForward();
5
});

Example: Simple Turtle Control 2

Move the turtle forward or backward depending on the button clicked.
1
// Move the turtle forward or backward depending on the button clicked.
2
button("forward", "Move Forward");
3
button("backward", "Move Backward");
4
onEvent("forward", "click", function(event) {
5
  moveForward();
6
});
7
8
onEvent("backward", "click", function(event) {
9
  moveBackward();
10
});

Syntax

1
button(id, text)

Parameters

NameTypeRequired?Description
idstringThe unique identifier for the button. The id is used for referencing the button in event handlers or other UI element modification functions. Must begin with a letter, contain no spaces, and may contain letters, digits, - and _.
textstringThe text displayed within the button.

Returns

No return value. Modifies screen only.

Tips

Found a bug in the documentation? Let us know at documentation@code.org


'via Blog this'
Post a Comment