关注图老师电脑网络栏目可以让大家能更好的了解电脑,知道有关于电脑的更多有趣教程,今天给大家分享Flash AS教程:对拖到指定区域小球计数-Flash actionscript教程,希望对大家能有一点小小的帮助。
【 tulaoshi.com - FLASH 】
今天帮网友做一个一个简单的效果,但用到了比较多的手段,所以记录一下:
要求将小球拖到指定区域,然后计数,如图:
时间轴:
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;
(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/flash/)}
}
function mc_u(e:MouseEvent) {
e.target.stopDrag();
var class_str:String=getQualifiedClassName (e.target);
var class_name=getDefinitionByName(class_str);
(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/flash/)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
www.Tulaoshi.com //改进:定义一个父亲给三个类:
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();
}
}
}
来源:http://www.tulaoshi.com/n/20160318/1888059.html
看过《Flash AS教程:对拖到指定区域小球计数-Flash actionscript》的人还看了以下文章 更多>>