Start coding the project
Our group have started to add code to our project. I use startDrag and stopDrag to make the coins are clickable and draggable. A hitTest for the movie clip pig_mc and coin_mc, if coin_mc hit pig_mc (depends on which coin you are clicking e.g. 10 cents coin), totalCoins will add 0.1, and the money_txt.text will display the amount of totalCoin as “you have 0.1 dollar(s)”.At this stage they are all work.
Code I have been used(only 10 cents here):
var totalCoins = 0;
money_txt.addEventListener(Event.ENTER_FRAME, addCoins);
function addCoins(evt:Event): void {
//click and drag coins
//10 cents
coin10_mc.buttonMode = true;
coin10_mc.addEventListener(MouseEvent.CLICK, clickHandler10Cents);
coin10_mc.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown10Cents);
coin10_mc.addEventListener(MouseEvent.MOUSE_UP, mouseUp10Cents);
function clickHandler10Cents(event:MouseEvent):void {
trace(“You clicked the 10 cents Coin”);
}
function mouseDown10Cents(event:MouseEvent):void {
coin10_mc.startDrag();
}
function mouseUp10Cents(event:MouseEvent):void {
coin10_mc.stopDrag();
if(coin10_mc.hitTestObject(pig_mc)){
coin10_mc.removeChildAt(0);
totalCoins +=0.10;
}
}
money_txt.text = “You have:”+ totalCoins +”dollars”;
}
The next problem I need to solve is addChild and removeChild, I can remove the coin_mc but I don’t know how add…so this application can only run for once and the totalCoins are 3.8 dollars.
This week is week 8, we still have 3 weeks time…not much.
