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