[Flash Basic theory Lesson 11] As text calculator [text class]

Source: Internet
Author: User
Tags border color character set

Back to "flash Basic Theory Class-Catalog"

This example introduces the application of the function in the program

Ideas:

1. Create four text boxes with as the first to enter numbers, the second to enter operators, and the third to enter numbers, and the last to output results.

2. Set a button (COUNT_BTN), press the operator followed by the second text box to compute the first and third text contents and output in the last text box.

3. The first text box is named "In1"

The second text box is named "Sign"

The third text box is named "In2"

The fourth text box is named "Out"

Executable program One:

var t_f:textformat = new TextFormat ();
T_f.size = 20;
Set the font in text format to 20
================ Sets the first text box ====================
_root.createtextfield ("in1", 1, 25, 50, 150, 25);
Create a text box, note that the y-coordinate of the further down text box is incremented
In1.setnewtextformat (T_f);
Assign a formatted text format to the text box
In1.type = "Input";
Set text box type to input
In1.background = true;
text box has a background color
In1.backgroundcolor = 0XFFFFFF;
Background color is white
In1.border = true;
text box has a border
In1.bordercolor = 0x0;
Border color is black
In1.maxchars = 7;
The maximum number of characters in a text box is 7
In1.restrict = "0-9";
The character set allowed in the text box is 0 to 9
============ Set the second text box (basic ibid.) ==============
_root.createtextfield ("Sign", 2, 25, 80, 150, 25);
Sign.setnewtextformat (T_f);
Sign.type = "Input";
Sign.background = true;
Sign.backgroundcolor = 0XFFFFFF;
Sign.border = true;
Sign.bordercolor = 0x0;
Sign.maxchars = 1;
Sign.restrict = "+*/\-";
============ Sets the third text box (basic ibid.) ==============
_root.createtextfield ("in2", 3, 25, 110, 150, 25);
In2.setnewtextformat (T_f);
In2.type = "Input";
In2.background = true;
In2.backgroundcolor = 0XFFFFFF;
In2.border = true;
In2.bordercolor = 0x0;
In2.restrict = "0-9";
In2.maxchars = 7;
============== Set Fourth output text box ===============
_root.createtextfield ("Out", 4, 25, 165, 150, 25);
Out.setnewtextformat (T_f);
Out.type = "dynamic";
Out.background = true;
Out.backgroundcolor = 0XFFFFFF;
Out.border = true;
Out.bordercolor = 0x0;
================ button is pressed and then calculated ================
Count_btn.onrelease = function () {
if (Sign.text = = "+") {
out.text = Int (in1.text) +int (In2.text);
}
if (Sign.text = = "-") {
out.text = Int (in1.text)-int (In2.text);
}
if (Sign.text = = "*") {
out.text = Int (in1.text) *int (In2.text);
}
if (Sign.text = = "/") {
out.text = Int (in1.text)/int (In2.text);
}
};

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.