闪光的ActionScript闪光、ActionScript

2023-09-09 21:32:12 作者:相思寄于海

这是我第一次到code的动作闪光。我想写一个闪光片段其工作方式的另一闪光剪辑父。我想写在父闪光灯功能,并调用子闪剪辑功能。例如,我想创建一个将场均得分为submitscore.php的动作。父只是一个控制器和孩子是我的游戏。我想比赛成绩发送到控制器,然后将其发送给我的PHP文件。你有什么样code或做什么?我真的不知道我要的是硬或容易的,因为这是我第一次;) 感谢名单提前

解决方案

  VAR游戏:对象;
私有函数sendToPHP(五:自定义事件):无效
{
    VAR得分:数= e.score;
    //发送
}
//将game.swf
VAR LDR:装载机=新的Loader();
的addChild(LDR);
ldr.contentLoaderInfo.addEventListener(引发Event.COMPLETE,的onLoad);
ldr.load(新的URLRequest(Game.swf));

私有函数的onLoad(五:事件):无效
{
    游戏=的LoaderInfo(e.target).content;
    game.addEventListener(sendScore,sendToPHP);
}

//Game.as
//调用这个只要你想送分给PHP
则dispatchEvent(新的自定义事件(sendScore,得分));

/ **
* CustomEvent.as应扩大事件和它的构造应更新公众
*属性评分:号码和通话超()的第一个参数。
*随意问你是否有实现自定义事件有任何怀疑。
* * /
 

It is my first time to code an actionscript for flash. I want to write a flash clip which works as a parent of another flash clip. I want to write a function in the parent flash, and call that function in the child flash clip. For example I wanna create an actionscript which sends game score to "submitscore.php". The parent is just a controller and the child is my game. I want to send game score to the controller, then send it to my php file. Do you have any sample code or something to do that? I really don't know what I want is hard or easy because it's my first time ;) thanx in advance

解决方案 ActionScript 3.0的新特性及新变化

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.
* */