How does one translate this code to ActionScript 3.0?

混江龙づ霸主 提交于 2019-12-25 02:02:48

问题


I'm stumped with this code - it seems that every time I port some of the reserved words of this AS2 code (what it does is to send mail using both Flash and PHP), I'm getting errors

stop();

var senderLoad:LoadVars = new LoadVars();
var receiveLoad:LoadVars = new LoadVars();

sender.onRelease = function() {
    senderLoad.theName = theName.text;
    senderLoad.theEmail = theEmail.text;
    senderLoad.theMessage = theMessage.text;
    senderLoad.sendAndLoad("http://leebrimelow.com/mailExample/send.php",receiveLoad);
}

receiveLoad.onLoad = function() {
    if(this.sentOk) {
        _root.gotoAndStop("success");
    }
    else {
        _root.gotoAndStop("failed");
    }
}
 Any idea how? 

回答1:


If you update LoadVars Object to As3 just use an UrlLoader Object like this code.

var mainLoader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("http://domain/mailExample/send.php");
var variables:URLVariables = new URLVariables();
    variables.theName = theName.text;
    variables.theEmail = theEmail.text;
    variables.theMessage = theMessage.text;
    request.method = URLRequestMethod.POST;
    request.data = variables;
    mainloader.addEventListener(Event.COMPLETE, handleComplete);
    mainLoader.load(request);




  private function handleComplete(event:Event):void {
        var loader:URLLoader = URLLoader(event.target);
   }



回答2:


I'm n't expert in AS2 but I can help you with the syntax of AS3 you need for this code try to see would help u it's the basic of the AS3 Concepts

mouseevent as3

Function As3

and that's AS3 function syntax

bldg1_thumb1.addEventListener(MouseEvent.CLICK, MyFunction);

function MyFunction (event:MouseEvent):void{
    gotoAndStop ("2");
}


来源:https://stackoverflow.com/questions/7450788/how-does-one-translate-this-code-to-actionscript-3-0

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