2009-12-08 77 views
0

这是我第一次为flash编写actionscript代码。我想写一个闪存剪辑作为另一个闪存剪辑的父级。我想在父闪光灯中写入一个功能,并在子闪存剪辑中调用该功能。例如,我想创建一个将游戏得分发送到“submitscore.php”的动作。父母只是一个控制者,孩子就是我的游戏。我想将游戏得分发送给控制器,然后将其发送到我的php文件。你有什么样的代码或者有什么要做的吗?我真的不知道我想要什么很难或容易,因为这是我第一次;) thanx提前Flash Actionscript

回答

1
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. 
* */ 
+0

thanx为您的答复。但是,是否可以写更多的细节,因为我在我的动作脚本中编写了这段代码,它有3个关于不在类中的函数的错误。我真的是新手。 thanx提前。 – AliBZ 2009-12-08 13:42:06

+0

您需要声明一个文档类并在其中编写函数。什么是错误信息?顺便说一下,代码是AS3。 – Amarghosh 2009-12-08 14:38:28

+1

是否可以用AS1编写! – AliBZ 2009-12-09 05:36:02