Public and private members

Source: Internet
Author: User
Flash MX 2004 Class members have the difference between public and private members, so how do we apply and differentiate them, here are a few simple examples to help you understand.

If not specifically specified, all members of the class are public, not specifically declared. But private members must be declared.

If the member is public, it can be invoked by the main class and Flash. If the members are private, they can only be accessed through the main class. Let's look at an example, which has a private method showsomething ().

Class Show {private Function showsomething () {Trace ("Sth");}

Then take a look at the following code:

var say:show = new show (); say. Showsomething ();

The code run will appear: "The ' is private and cannot to be accessed." This is because we cannot invoke private members.

If you modify this, there is no problem because the main class is called:

var say = new show (); say. Showsomething ();

Now we should have some understanding of the public and private members.

If it is a class that calls itself, then there is no problem, see this example:

Class Show {private Function showsomething () {Trace ("Sth");} Public Function ShowSomething2 () {showsomething ();}}

Then, this program will work:

var say:show = new show (); say. ShowSomething2 ();

Because we're calling a public member.

You can do more exercises and get to know the difference between public and private members.



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.