Flash as learning: OOP Classic Tutorials-as2.0 Chapter

Source: Internet
Author: User
Tags constructor
Tutorial This is from the talent translation of the article cut, but the source program has errors, I changed a bit. Conveniently hangs the original tutorial and the source file (this is one to look at the Flashpaper dozen!) )。 Last listen to a C # lecture, with this vehicle and car; hehe, see how to drive our lovely flash with class.
The project has two categories: Vehicle (superclass) and car (subclass);

Class vehiche{
private Var _npassengers:number;
public Var _nmiles:number;
public Var _ninterval:number;
function Vehicle (npassengers:number,nmiles:number) {
_npassengers=npassengers;
_nmiles=nmiles;
}
...................}
Class Car extends vehiche{
private Var _smake:string;
private Var _smode1:string;
private Var _nyear:number;
function car (smake:string, smode1:string,nyear:number,class car extends vehiche{
private Var _smake:string;
private Var _smode1:string;
private Var _nyear:number;
function car (smake:string, Smode1:string,nyear:number,npassengers:number,nmiles:number) {
Super. Vehicle (npassengers,nmiles);//Super Class
_npassengers=npassengers;
_nmiles=nmiles;
_smake=smake;
_smode1=smode1;
Year=nyear;
}number,nmiles:number) {
Super (Npassengers,nmiles);
_smake=smake;
_smode1=smode1;
Year=nyear;
}
...................}

This is the original, and the constructor in the car class inherits the Npassengers,nmiles parameter from the vehicle constructor. With super (npassengers,nmiles);
As a result, I knocked over a run, no, trace (car.nmiles) =undefined;
After reading the document carefully, I became aware of the use of super, and instead
Super. Vehicle (Npassengers,nmiles);
The result is successful, haha, be the talent to play a pass, think or oneself good from the nature of the good, learn oop see Java bar, hehe!
source file Download: (including source tutorial)
Click to browse the file



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.