这是我第一次为flash编写actionscript。我想写一个闪光灯剪辑,作为另一个闪光灯剪辑的父母工作。我想在父flash中编写一个函数,然后在子flash剪辑中调用该函数。例如,我想创建一个将游戏分数发送到"submitscore.php“的动作脚本。父母只是一个控制器,孩子是我的游戏。我想发送游戏分数到控制器,然后发送到我的php文件。你有没有什么样例代码或者其他东西可以做到这一点?我真的不知道我想要的是难是容易,因为这是我的第一次;)提前谢谢
发布于 2009-12-08 21:02:00
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.
* */https://stackoverflow.com/questions/1866526
复制相似问题