Simple counter code of flash as3.0

Source: Internet
Author: User
Tags rar

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);
Class:
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 () {
}
}
}

The function of the class is very simple, mainly used for counting and judging!
Desktop. RAR: Desktop. rar

Improvement: Definition of a father to three classes:
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 ();
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.