不用库符号附加影片简辑类的方法(as2)

      Flash 2004-2-4 10:44
Peter Joel 的方法:
class Rectangle extends MovieClip{
static var symbolName:String = "__Packages.Rectangle";
static var symbolOwner:Function = Rectangle;

public var width:Number = 100;
public var height:Number = 100;
public var color:Number = 0;

function Rectangle (){
draw();
}

function draw():Void{
beginFill(color);
moveTo(0,0);
lineTo(width, 0);
lineTo(width, height);
lineTo(0, height);
lineTo(0, 0);
endFill();
}

// associate the symbol to the class when the class is defined
static var symbolLinked = Object.registerClass(symbolName, symbolOwner);
}

//用法:
import Rectangle;
var initObjbject = {width:150, height:80, color:0xFF0000};
attachMovie(Rectangle.symbolName, "rect_mc", 1, initObj);

Dave Yang 的补充:
class Actor extends MovieClip {
static var id = (id="__Packages.Actor")+(Object.registerClass(id,Actor)?"":"");

public function Actor() {
trace("Action!");
}
}

//用法:
import Actor;
attachMovie(Actor.id, "_mc", 1);

Bokel 的方法:
class Triangle extends MovieClip {
//
static function createInstance ( base_mc, name, depth){
var saveProto = MovieClip.prototype;
MovieClip.prototype = Triangle.prototype;
var mc = base_mc.createEmptyMovieClip( name, depth)
MovieClip.prototype = saveProto;
Function(Triangle).apply( mc)
return mc;
}
//
public var width:Number = 100;
public var height:Number = 100;
public var color:Number = 0;
//
//
function Triangle() {
draw();
}
//
function draw():Void {
beginFill( color);
moveTo(0, 0);
lineTo(width, 0);
lineTo(width/2, height);
lineTo(0, 0);
endFill();
}
}

//用法:
Triangle.createInstance(this, "tri_mc", 1);

//转自丹姐的BLOG http://www.dengjie.com/
标签集:TAGS:
回复Comments() 点击Count()

回复Comments

{commentauthor}
{commentauthor}
{commenttime}
{commentnum}
{commentcontent}
作者:
{commentrecontent}
}