代码之家  ›  专栏  ›  技术社区  ›  AliBZ

flash动作脚本

  •  0
  • AliBZ  · 技术社区  · 15 年前

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

    1 回复  |  直到 15 年前
        1
  •  1
  •   Amarghosh    15 年前
    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.
    * */