I have this catcher game, where soda bottles falls on to the stage, and we use a character as a cursor to catch it. But all the actionscript is built in already into the file internally. But I was asked to put the two classes I use (the cursor and the falling soda bottles) in an external classfile.
And since I'm really new to OOP I really don't understand how to do this. So, how do you move an internal actionscript for a class into an external actionscript file?
Thanks in advanced, for considering to help :p
The code is bellow if it helps.
var koyupo:Koyupo;
var createsodaID:uint;
var gamespeed:uint;
var score:uint=0;
function startGame () :void {
// create the character as a cursor
koyupo= new Koyupo();
koyupo.x=200;
koyupo.y=270;
addChild(koyupo);
// listens for a mouse move event to move the koyupo
stage.addEventListener(MouseEvent.MOUSE_MOVE, movekoyupo);
Mouse.hide();
gamespeed=500;
createsodaID=setInterval (createsoda, gamespeed);
//setting the ammount displayed on screen to be 0
droppedtext.text=caughttext.text='0';
}
function movekoyupo (e:MouseEvent) :void{
// move koyupo according to the mouse movement
koyupo.x=this.mouseX;
e.updateAfterEvent ();
}
function getRandomNumber ( low:Number , high:Number):Number
{
var randomNumber:Number = Math.random()*(high-low) +low;
return randomNumber;
}
function createsoda () :void {
//creating falling soda bottles
var soda:Soda= new Soda ();
soda.y=-50;
trace(getRandomNumber(50,900));
soda.x=getRandomNumber(100 , 500);
soda.addEventListener(Event.ENTER_FRAME, dropsoda);
addChild(soda);
}
function dropsoda (e:Event):void{
var mc:Soda=Soda(e.target);
mc.y+=10;
if(mc.hitTestObject (koyupo)){
caught (mc);
}else if (mc.y>stage.stageHeight) {
dropped (mc);
}
}
function caught (mc:Soda):void{
mc.removeEventListener(Event.ENTER_FRAME,dropsoda);
removeChild(mc);
caughttext.text=String(Number(caughttext.text)+1);
if(caughttext.text=='35'){
proceed();
}
}
function dropped (mc:Soda):void{
mc.removeEventListener(Event.ENTER_FRAME,dropsoda);
removeChild(mc);
droppedtext.text=String(Number(droppedtext.text)+1);
if(droppedtext.text=='5'){
gameOver();
}
}
function gameOver() :void{
score=Number(caughttext.text);
stage.removeEventListener(MouseEvent.MOUSE_MOVE,movekoyupo);
removeChild(koyupo);
clearInterval(createsodaID);
removeChild(caughttext);
removeChild(droppedtext);
while(numChildren>0) {
getChildAt (0) .removeEventListener(Event.ENTER_FRAME, dropsoda);
removeChildAt(0);
}
Mouse.show();
gotoAndStop('gameover');
}
function proceed() :void{
score=Number(caughttext.text);
stage.removeEventListener(MouseEvent.MOUSE_MOVE,movekoyupo);
removeChild(koyupo);
clearInterval(createsodaID);
removeChild(caughttext);
removeChild(droppedtext);
while(numChildren>0) {
getChildAt (0) .removeEventListener(Event.ENTER_FRAME, dropsoda);
removeChildAt(0);
}
Mouse.show();
gotoAndStop('win');
}
startGame();