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.
* */
thanx爲您的答覆。但是,是否可以寫更多的細節,因爲我在我的動作腳本中編寫了這段代碼,它有3個關於不在類中的函數的錯誤。我真的是新手。 thanx提前。 – AliBZ 2009-12-08 13:42:06
您需要聲明一個文檔類並在其中編寫函數。什麼是錯誤信息?順便說一下,代碼是AS3。 – Amarghosh 2009-12-08 14:38:28
是否可以用AS1編寫! – AliBZ 2009-12-09 05:36:02