An Image/Link below is provided (as is) to download presentation
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.Content is provided to you AS IS for your information and personal use only.Download presentation by click this link.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.During download, if you can't get a presentation, the file might be deleted by the publisher.
class People{ var fullName:String; var age:Number; } 说明: 1、自定义类以class关键字开头,类名称的第一个英文字 母通常用大写。 2、自定义类一定要写在影片外部,扩展名为.as 的纯文 本文件中。 3、在保存AS文件时,文件名应该和自定义类的类名一模 一样,包括大小写,且必须存放在与应用此类的.fla 文件相同的文件夹中。
编写好自定义的 People类后,就可在Flash影片中,通过此People类来建立人员数据。 方法为:在影片的关键帧上输入下面的代码 var user1:People=new People(); user1.fullName=“李红"; user1.age=19; 注意:此影片文件一定要保存在和People.as相同的文件夹中。 虽然自定义类写在影片外部,但是在导出影片文件时,外部代码就会和其它代码一起编译到.swf里面,所以在上传.swf影片时,并不需要另外传递.as文件。
8.1.2创建类的属性和方法 类的成员包括属性和方法,所有属性和方法都必须在类体(大括号)内声明,否则编译时将出现错误。 在AS文件中声明类的属性的方式与在“动作”面板中声明变量的方式相似,声明类的方法的方式与在“动作”面板中声明函数的方式相似。 如:class People{ var fullName:String; var age:Number; function showInfo(){ //方法定义 } }
8.1.3构造函数 构造函数是用于初始化类的属性和方法的函数,类的构造函数是一个特殊的函数,使用 new 运算符创建类的实例时将自动调用该函数。 构造函数的名称与包含它的类的名称相同。 如:class People{ var fullName:String; var age:Number; function People(n:String,a:Number){ this. fullName=n; this.age=a; } } 调用时:var user1:People=new (“小赵”,18);
可以使用 public 或 private 成员属性来指定公共或私有成员。 例如,以下代码声明一个私有变量(一个属性)和一个私有方法(一个函数)。 class LoginClass { private var userName:String; private function getUserName (){ return this.userName; } }
8.2.1Array类 Array 类使你可以访问并操作数组,要使用数组需先构造数组。请使用构造函数 new Array() 格式为: var 数组名= new Array(); var 数组名= new Array(元素的个数); var 数组名= new Array(初值1,初值2,初值3,初值4….);
8.2.6Number类 Number 类是 Number 数据类型的简单包装对象。使用与 Number 类关联的方法和属性可以操作基本数值。此类与 JavaScript Number 类完全相同。 Number 类的方法: toString() :返回 Number 对象的字符串表示形式。 valueOf() :返回 Number 对象的原始值。
8.3.3 Color类 Color 类可用于获取和设置影片剪辑对象的 RGB 颜色值。 必须使用构造函数 new Color() 创建 Color 对象后,才可调用其方法。 格式为: 对象名= new Color(目标实例名); 对象名.方法 说明:目标实例名是指由Color对象控制颜色的影片剪辑实例的路径。
Color 类的方法有4个: setRGB() :为 Color 对象设置 RGB 值的十六进制表示形式。 setTransform() :为 Color 对象设置颜色转换。 getRGB(): 返回由最后一次 setRGB() 调用设置的 RGB 数值。 getTransform() :返回由最后一次 setTransform() 调用设置的转换信息。 如:var myColor = new Color(target); myColor .setRGB(0x112233); 0x 告知编译器该数字是十六进制。