当前位置: 首页 > 图文教程 > Flash动画 > Flash动画制作 > AS2.0的私有,公有成员,类继承和as嵌套
Flash动画制作 中的 AS2.0的私有,公有成员,类继承和as嵌套
class test_private
{
private var tmp1:String; //声明tmp为私有变量
public var tmp2:String; //不加public默认都为公有变量
function test_private()
{
tmp1 = "私有变量"; //赋值
tmp2 = "公有变量";
}
}
var myclass:test_private = new test_private();
trace("tmp1=" + myclass.tmp1);
trace("tmp2=" + myclass.tmp2);
var myclass = new test_private();
trace("tmp1=" + myclass.tmp1);
trace("tmp2=" + myclass.tmp2);
//建立一个test1.as的类文件
class test1
{
private var hide_txt:String;
private var show_txt:String;
private function hide_sq()
{
_root.square._visible = false;
}
private function show_sq()
{
_root.square._visible=true;
}
}
class test2 extends test1
{
function test2()
{
hide_txt = "隐藏"; //继承了test1的变量,我们可以给他赋值
show_txt="显示";
}
}
on (release) {
var myclass= new test2();
myclass.hide_sq(); //继承了test1.as中的方法
txt.text = myclass.hide_txt;
//这是在test2.as中赋值的test1.as中的变量,说明继承之后变更为自己的特性
}
on (release) {
var myclass = new test2();
myclass.show_sq();
txt.text = myclass.show_txt;
}
评论 (0) All