AS3的表单登录

web开发常用的表单登录,一般就是提交form数据,而在AS中,换了一种形式,但实质都是提交key-value:

public function submit()

{

    var variables:URLVariables = new URLVariables;

    variables.username = form.username.text;

    variables.password = form.password.text;

    sendRequest(' url ', variables);

}



public function sendRequest(url: String, params: URLVariables)

{

    var request:URLRequest = new URLRequest(url);

    request.data = params;

    request.method = URLRequestMethod.POST;



    var loader: URLLoader = new URLLoader();

    loader.addEventListener(Event.COMPLETE, onLoadCompleted);

    loader.load(request);

}



public function onLoadCompleted(e: Event)

{

    var code: String = e.target.data as String;

    switch(code){

        case '0':

            trace('用户名或密码错误');

            break;

        case '1':

            trace('登录成功');

            break;

    }

}


form 是一个MC,里面有两个TextField对象,一个叫做username,另一个叫做password,这样便模拟了表单。

你可能感兴趣的:(as3)