Code for creating a jukebox machine in actionscript 3
Hi, I am trying to create a code in actionscript 3 where I can put a coin in a jukebox and it will credit the machine. So far I have the code to drag each coin however I cannot figure out how one I put the coin in the coinslot it will go back to its place and also credit the machine. I want the amount of money I put in to be displayed on the screen. For example if I put a nickel in it will display 5 on the machine. I want the machine to allow the person to play a song once 50 cents have been put in the machine. Please help I cannot figure out how to code this.
This is what I have so far:
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class DragCoin extends MovieClip
{
protected var oldX:uint;
protected var oldY:uint;
public function DragCoin()
{
oldX = this.x;
oldY = this.y;
trace("Coin Constructor");
buttonMode = true;
this.addEventListener(MouseEvent.MOUSE_DOWN, dragingCoin);
}
public function dragingCoin(me:MouseEvent):void
{
trace("dragging");
stage.addChild(this);
startDrag();
this.addEventListener(MouseEvent.MOUSE_UP, dropCoin);
}
public function dropCoin(mouseEvent:MouseEvent):void
{
this.removeEventListener(MouseEvent.MOUSE_UP, dropCoin);
stopDrag();
trace("dropTarget>"+dropTarget);
if (dropTarget != null)
{
if (dropTarget.parent.name == "Coinslot")
{
trace("found Coinslot");
putInCoinslot();
}
else
returnToOldXY();
}
else
{
trace("Dropped on nothing");
returnToOldXY();
}
}
public function returnToOldXY():void
{
this.x = oldX;
this.y = oldY;
}
public function putInCoinslot():void
{
this.scaleX = this.scaleY = 0.3;
this.alpha = 0.4;
buttonMode = false;
this.removeEventListener(MouseEvent.MOUSE_DOWN, dragingCoin);
}
}
}