Programming Basics (4: objects)

Source: Internet
Author: User
Tags constructor

In the object-oriented programming, we will organize the information through grouping into classes. you can create multiple instances of a class, which is also called an object. you can create your own class (custom object) or use the built-in action script class (pre-defined object). The built-in class is located in the "object" folder on the "action" panel. When you define a class, you need to define all attributes (features) and methods (actions) of each object created by the class, just like defining the objects of life. For example, you can say that a person has attributes such as gender, height, and color, as well as methods such as conversation, walking, and throwing. "Person" is a class, and each person is an object or an instance of this class. "James is a one-meter-eight-year-old boy." He has attributes such as gender, height, and other methods to speak. In this example, "Michael" is an object. for another example, we have defined the "talking girl" class, "talking girl", and "talking girl" as an example.
Objects in action scripts can be pure data containers, or they can be graphically represented as video clips, buttons, or text fields on the stage. All video clips are built-in class MovieClip instances, and all buttons are built-in class buttons instances. Each video editing instance contains all attributes of the MovieClip class (for example, _ height, _ rotation, _ totalframes) and all methods (for example, gotoAndPlay, loadMovie, and startDrag ). Now, do you understand? However, these are built-in objects and pre-defined objects.
To define a class, you can create a class namedConstructor. (The built-in class has built-in constructor .) You can generate your own instance like a predefined object. When defining an object, you can also define attribute methods for your own defined object. the defined object is actually to build a function for the defined object. Such a function is called "build function ". you can describe the attributes and methods of an object in the function. after the definition is complete, you can create an instance of the defined object in a future program for future convenience. the name of the constructed function is usually the same as that of the object. Syntax:Function name (parameter) {this. Parameter =? ::}WhereThe function name is the object name.. The parameter can be interpretedAttributeWhen an object is built, flash automatically generates a keyword"This"To represent this object, so"This. Parameter =?"The parameter attribute of this [color = # D from 143C] object is defined as follows "? "Action or value. "..." Is a ellipsis, indicating that more can be defined.
For example, if you need information about a bicycle rider in your video, you can create a constructor function "bike ride", which has attributes "time" and "distance ", and how to tell you the speed of the bicycle ":
Function bike ride[Function, object name](Min, km[Parameters]) {This. Time = minute[Value or action]This. Distance = km; this. Speed = function () {return this. Distance/this. Time ;};[This is a user-defined function. The running result of the function is the return distance/time value.] }
Here, for everyone to understand, I use the defined object function parameters and other Chinese characters. During programming, remember to comply with the standard of definition identifiers. (letters, numbers, and underscores. starts with a letter or underscore ).

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.