function mc_press(_mc:MovieClip) {
_mc.addEventListener(flash.events.MouseEvent.MOUSE_DOWN,d_f);
}
function d_f(e:MouseEvent) {
var str:String=e.target.name.slice(0,e.target.name.length-3);
var myclass=getDefinitionByName(str);
var my_mc=new myclass();
my_mc.startDrag(true);
addChild(my_mc);
my_mc.addEventListener(flash.events.MouseEvent.MOUSE_DOWN,mc_d);
my_mc.addEventListener(flash.events.MouseEvent.MOUSE_UP,mc_u);
}
function mc_d(e:MouseEvent) {
e.target.startDrag();
if (fang_mc.hitTestPoint(e.target.x,e.target.y)) {
e.target.isHitTest=true;
} else {
e.target.isHitTest=false;
}
}
function mc_u(e:MouseEvent) {
e.target.stopDrag();
var class_str:String=getQualifiedClassName (e.target);
var class_name=getDefinitionByName(class_str);
if (!e.target.isHitTest) {
if (fang_mc.hitTestPoint(e.target.x,e.target.y)) {
class_name.num++;
}
} else {
if (!fang_mc.hitTestPoint(e.target.x,e.target.y)) {
class_name.num--;
}
}
back_txt.text=String(back.num);
blue_txt.text=String(blue.num);
red_txt.text=String(red.num);
}
mc_press(back_mc);
mc_press(blue_mc);
mc_press(red_mc);
类:
package {
import flash.display.MovieClip;
public class back extends MovieClip {
public static var num:int=0;
public var isHitTest:Boolean=false;
public function back() {
}
}
}
package {
import flash.display.MovieClip;
public class blue extends MovieClip {
public static var num:int=0;
public var isHitTest:Boolean=false;
public function blue() {
}
}
}
package {
import flash.display.MovieClip;
public class red extends MovieClip {
public static var num:int=0;
public var isHitTest:Boolean=false;
public function red() {
}
}
}
类的功能很简单,主要用于计数和判断!
桌面.rar:桌面.rar
//改进:定义一个父亲给三个类:
package {
import flash.display.MovieClip;
public class color extends MovieClip {
public var isHitTest:Boolean=false;
public function color() {
}
}
}
package {
import flash.display.MovieClip;
public class back extends color {
public static var num:int=0;
public function back() {
}
}
}
package {
import flash.display.MovieClip;
public class blue extends color {
public static var num:int=0;
public function blue() {
}
}
}
package {
import flash.display.MovieClip;
public class red extends color {
public static var num:int=0;
public function red() {
super();
}
}
}