我有這個捕手遊戲,汽水瓶落在舞臺上,我們用一個角色作爲遊標來捕捉它。但是所有的動作腳本都已內置到文件中。但我被要求將我使用的兩個班級(光標和倒下的汽水瓶)放在外部的班級文件中。如何將內部函數移動到外部ActionScript 3類文件?
而且由於我真的是OOP的新手,我真的不知道該怎麼做。那麼,如何將一個類的內部動作移動到一個外部動作文件中呢?
在先進的感謝,爲考慮到幫助:P
的代碼波紋管是否有幫助。
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();
此代碼目前位於FLA文檔某處的時間軸上嗎? – 2010-10-15 11:06:45
是的,它目前在時間軸上。如果我上傳Flash文件會有幫助嗎? – steph 2010-10-15 11:34:55