第一个flash AS代码
package fla {
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.utils.clearInterval;
import flash.utils.setInterval;
public class Main extends MovieClip {
public var msgwrong:msg_wrong;
public var msgright:msg_right;
public var WIDTH:Number=700;
public var HEIGHT:Number=800;
public var gou1:dagou=new dagou();
public var gou2:dagou=new dagou();
public var gou3:dagou=new dagou();
public var gou4:dagou=new dagou();
public var bs:backspace;
public var No0:num0;
public var No1:num1;
public var No2:num2;
public var No4:num4;
public var No5:num5;
public var No6:num6;
public var New_kb:Array;
public var No7:num7;
public var No8:num8;
public var No9:num9;
public var No3:num3;
public var Check:check;
public var Num_kb:Array;
public var numkb_flag:Object;
public var num_id;
public var Local_numkb:Array;
public var obj:Object=new Object();
public var arrMc:Array;
public function Main() {
this.gotoAndPlay(1);
addFrameScript(0, Init);
}
public function Init():void{
arrMc=new Array('gou1','gou2','gou3','gou4');
for(var i:int =0; i<arrMc.length;i++)
{
switch(i){
case 0:
MovieClip(this[arrMc[i]]).x = 200;
MovieClip(this[arrMc[i]]).y = 240;
break;
case 1:
MovieClip(this[arrMc[i]]).x = 550;
MovieClip(this[arrMc[i]]).y = 240;
break;
case 2:
MovieClip(this[arrMc[i]]).x = 200;
MovieClip(this[arrMc[i]]).y = 380;
break;
case 3:
MovieClip(this[arrMc[i]]).x = 550;
MovieClip(this[arrMc[i]]).y = 380;
break;
}
MovieClip(this[arrMc[i]]).visible = true;
MovieClip(this[arrMc[i]]).mouseEnabled = true;
MovieClip(this[arrMc[i]]).mouseChildren = true;
MovieClip(this[arrMc[i]]).name='gou'+i;
//MovieClip(this[arrMc[i]]).currentFrame ==1;
MovieClip(this[arrMc[i]]).stop();
//MovieClip(this[arrMc[i]]). = i+1;
MovieClip(this[arrMc[i]]).buttonMode = true;
MovieClip(this[arrMc[i]]).addEventListener(MouseEvent.MOUSE_OVER,TurnBig);
MovieClip(this[arrMc[i]]).addEventListener(MouseEvent.MOUSE_OUT,TrunSmall);
MovieClip(this[arrMc[i]]).addEventListener(MouseEvent.CLICK,RightClick);
addChild(this[arrMc[i]]);
//addChild(arrMc[i]);
}
Num_kb = new Array(No0, No1, No2, No3, No4, No5, No6, No7, No8, No9, bs);
Local_numkb = new Array(11);
numkb_flag = 0;
InitFrame();
}
public function TurnBig(event:MouseEvent){
var dg:dagou=event.currentTarget as dagou;
dg.gotoAndPlay(2);
dg.stop();
}
public function TrunSmall(event:MouseEvent){
var dg:dagou=event.currentTarget as dagou;
dg.gotoAndPlay(1);
dg.stop();
}
public function InitFrame():void{
var _loc_1:int = 0;
while (_loc_1 < 11)
{
Num_kb[_loc_1].addEventListener(MouseEvent.MOUSE_DOWN, num_kb1);
Local_numkb[_loc_1] = Num_kb[_loc_1].x;
_loc_1++;
}
Check.addEventListener(MouseEvent.MOUSE_DOWN,chkSubmit);
}
public function num_kb1(event:MouseEvent)
{
var temp:int;
var num_id:int;
var back:Function;
var i:int;
var evt:* = event;
back = function ()
{
clearInterval(num_id);
Num_kb[temp].y = Num_kb[temp].y + Num_kb[temp].height;
return;
}// end function
;
temp;
num_id;
var _loc_3:* = search1(evt.target.x);
trace(evt.target.x);
temp = search1(evt.target.x);
//txtJG。text=String(temp);
var tf:*=this.getChildByName("txtJG")
tf.text=temp.toString();
//addChild(tf);
trace(tf.text);
trace(temp);
i;
if (temp != 10)
{
Num_kb[temp].y = Num_kb[temp].y - Num_kb[temp].height;
num_id = setInterval(back, 500);
}
return;
}// end function
public function search1(param1:Number) : int
{
var _loc_2:int = 0;
var _loc_3:int = 0;
var _loc_4:int = 0;
_loc_2 = 0;
_loc_3 = 0;
_loc_4 = 10;
while (_loc_3 <= _loc_4)
{
_loc_2 = (_loc_3 + _loc_4) / 2;
if (Local_numkb[_loc_2] == param1)
{
break;
continue;
}
if (Local_numkb[_loc_2] > param1)
{
_loc_4 = _loc_2 - 1;
continue;
}
if (Local_numkb[_loc_2] < param1)
{
_loc_3 = _loc_2 + 1;
}
}
return _loc_2;
}// end function
public function chkSubmit(event:MouseEvent):void{
var flg:Boolean=false;
trace('commit');
if(gou2.currentFrame==3){
flg=true;
}
var tf:*=this.getChildByName("txtJG")
if(tf.text!=3){
flg=false;
}
trace(flg);
trace(gou2.currentFrame);
if(flg){
msgright=new msg_right();
msgright.x=400;
msgright.y=400;
addChild(msgright);
setInterval(rmveCld,2000);
}else{
msgwrong=new msg_wrong();
msgwrong.x=400;
msgwrong.y=400;
addChild(msgwrong);
setInterval(rmveCld,2000);
}
}
public function ClearGou():void{
for(var i=0;i<4;i++){
var obj:dagou= this.getChildByName("gou"+i) as dagou;
obj.gotoAndPlay(1);
obj.stop();
}
}
//点击对了
public function RightClick(e:Event){
ClearGou();
var dg:dagou =e.currentTarget as dagou;
dg.gotoAndPlay(3);
dg.stop();
dg.removeEventListener(MouseEvent.MOUSE_OVER,TurnBig);
dg.removeEventListener(MouseEvent.MOUSE_OUT,TrunSmall);
}
public function rmveCld(){
if(msgwrong!=null){
this.removeChild(msgwrong);
}
if(msgright!=null){
this.removeChild(msgright);
}
clearInterval(num_id);
}
}
}
纯代码 为了后面用做记录 关键的获取对象 getChildByName