返回列表 回復 發帖

[問題] AS3 加法的互動元件

各位前輩們,小弟目前正在試做一個簡單加法的互動元件
因為是剛開始做sample檔所以裡面的元件不多,

三個可拖移元件one_mc(數字1), two_mc(數字2), three_mc(數字3)

被加數box1_mc 加數box2_mc 以及 秀出加起來的和的answer_txt

小弟我是想要“拖移數字1或數字2、數字3到box1_mc或box2_mc裡就會算出答案,
比例1+2=3或2+1=3..等
結果只要是拖到“3”,答案就是秀不出來,如3+1秀不出答案,
請各位前輩指導指導,感謝萬分。
以下是我的程式內容:
<<===========================================================>>

import flash.events.MouseEvent;

//----------------數字方塊拖移------------------\\
one_mc.addEventListener(MouseEvent.MOUSE_DOWN,startDragOne);
one_mc.addEventListener(MouseEvent.MOUSE_UP,stopDragOne);
two_mc.addEventListener(MouseEvent.MOUSE_DOWN,startDragTwo);
two_mc.addEventListener(MouseEvent.MOUSE_UP,stopDragTwo);
three_mc.addEventListener(MouseEvent.MOUSE_DOWN,startDragThree);
three_mc.addEventListener(MouseEvent.MOUSE_UP,stopDragThree);

function startDragOne(Event:MouseEvent):void
{

one_mc.startDrag();
}

function stopDragOne(Event:MouseEvent):void
{

one_mc.stopDrag();

Box1addition();

Box2addition();
}

function startDragTwo(Event:MouseEvent):void
{

two_mc.startDrag();
}

function stopDragTwo(Event:MouseEvent):void
{

two_mc.stopDrag();

Box1addition();

Box2addition();
}

function startDragThree(Event:MouseEvent):void
{

three_mc.startDrag();
}

function stopDragThree(Event:MouseEvent):void
{

three_mc.stopDrag();

Box1addition();

Box2addition();
}

var box1Temp:Number;
var box2Temp:Number;

function Box1addition():void
{


if (one_mc.hitTestObject(box1_mc))

{

box1Temp = 1;

}

else if (two_mc.hitTestObject(box1_mc))

{

box1Temp = 2;

}

else if (three_mc.hitTestObject(box1_mc))

{

box1Temp = 3;

}

else

{

box1Temp = 0;

}



BoxTotalAnswer();
}

function Box2addition():void
{


if (one_mc.hitTestObject(box2_mc))

{

box2Temp = 1;

}

else if (two_mc.hitTestObject(box2_mc))

{

box2Temp = 2;

}

else if (three_mc.hitTestObject(box2_mc))

{

box2Temp = 3;

}

else

{

box2Temp = 0;

}



BoxTotalAnswer();
}

function BoxTotalAnswer():void
{

var boxTotal:Number = 0;

boxTotal = box1Temp + box2Temp;

trace(boxTotal);

boxTotal.toString();

answer_txt.text = String(boxTotal);
}
<<===========================================================>>
附件: 您所在的用戶組無法下載或查看附件
已解決了,還是靠自己才是王道
返回列表