2009-12-08 159 views
0

這是我第一次爲flash編寫actionscript代碼。我想寫一個閃存剪輯作爲另一個閃存剪輯的父級。我想在父閃光燈中寫入一個功能,並在子閃存剪輯中調用該功能。例如,我想創建一個將遊戲得分發送到「submitscore.php」的動作。父母只是一個控制者,孩子就是我的遊戲。我想將遊戲得分發送給控制器,然後將其發送到我的php文件。你有什麼樣的代碼或者有什麼要做的嗎?我真的不知道我想要什麼很難或容易,因爲這是我第一次;) thanx提前Flash Actionscript

回答

1
var game:Object; 
private function sendToPHP(e:CustomEvent):void 
{ 
    var score:Number = e.score; 
    //send it 
} 
//load the game.swf 
var ldr:Loader = new Loader(); 
addChild(ldr); 
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoad); 
ldr.load(new URLRequest("Game.swf")); 

private function onLoad(e:Event):void 
{ 
    game = LoaderInfo(e.target).content; 
    game.addEventListener("sendScore", sendToPHP); 
} 

//Game.as 
//call this whenever you want to send score to php 
dispatchEvent(new CustomEvent("sendScore", score)); 

/** 
* CustomEvent.as should extend Event and its constructor should update the public 
* property score:Number and call super() with the first parameter. 
* Feel free to ask if you have any doubts implementing custom events. 
* */ 
+0

thanx爲您的答覆。但是,是否可以寫更多的細節,因爲我在我的動作腳本中編寫了這段代碼,它有3個關於不在類中的函數的錯誤。我真的是新手。 thanx提前。 – AliBZ 2009-12-08 13:42:06

+0

您需要聲明一個文檔類並在其中編寫函數。什麼是錯誤信息?順便說一下,代碼是AS3。 – Amarghosh 2009-12-08 14:38:28

+1

是否可以用AS1編寫! – AliBZ 2009-12-09 05:36:02