Flash Actionscript

老子叫甜甜 提交于 2019-12-12 04:49:59

问题


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


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


来源:https://stackoverflow.com/questions/1866526/flash-actionscript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!