首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Flash Actionscript

Flash Actionscript
EN

Stack Overflow用户
提问于 2009-12-08 20:01:55
回答 1查看 314关注 0票数 0

这是我第一次为flash编写actionscript。我想写一个闪光灯剪辑,作为另一个闪光灯剪辑的父母工作。我想在父flash中编写一个函数,然后在子flash剪辑中调用该函数。例如,我想创建一个将游戏分数发送到"submitscore.php“的动作脚本。父母只是一个控制器,孩子是我的游戏。我想发送游戏分数到控制器,然后发送到我的php文件。你有没有什么样例代码或者其他东西可以做到这一点?我真的不知道我想要的是难是容易,因为这是我的第一次;)提前谢谢

EN

回答 1

Stack Overflow用户

发布于 2009-12-08 21:02:00

代码语言:javascript
复制
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.
* */
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1866526

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档