as3.0英文帮助摘录(一)--关于package
sshong 发表于2007年5月29日 17:32:00 更新于2007年5月29日 17:33:00
一、When a package is created, the default access specifier for all members of that package is internal, which means that, by default, package members are only visible to other members of that package. If you want a class to be available to code outside the package, you must declare that class to be public. For example, the following package contains two classes, SampleCode and CodeFormatter:

// SampleCode.as file
package samples
{
    public class SampleCode {}
}

// CodeFormatter.as file
package samples
{
    class CodeFormatter {}
}


The SampleCode class is visible outside the package because it is declared as a public class. The CodeFormatter class, however, is visible only within the samples package itself. If you attempt to access the CodeFormatter class outside the samples package, you will generate an error, as the following example shows:

import samples.SampleCode;
import samples.CodeFormatter;
var mySample:SampleCode = new SampleCode(); // okay, public class
var myFormatter:CodeFormatter = new CodeFormatter(); // error


If you want both classes to be available outside the package, you must declare both classes to be public. You cannot apply the public attribute to the package declaration.

二、Programmers with a C++ background often confuse the import statement with #include. The #include directive is necessary in C++ because C++ compilers process one file at a time, and will not look in other files for class definitions unless a header file is explicitly included. ActionScript 3.0 has an include directive, but it is not designed to import classes and packages. To import classes or packages in ActionScript 3.0, you must use the import statement and place the source file that contains the package in the class path.
标签:无分类:As3&Flex阅读:2634
评论
暂无评论
添加评论
您的大名,限长10汉字,20英文(*)
电子信箱(*)
您的网站
正文,限长500汉字,1000英文(*)
验证码(*) 单击刷新验证码
联系我
博客订阅