Flash AS3类

时间:2016-04-09 07:55:49

标签: actionscript-3 flash

所以我是Flash新手,我目前正在学习有关登录和注册的教程。

我遵循的教程有一个外部AS文件,如下所示:

我在给定的空格中键入类的名称。到目前为止,当我运行程序时,它给了我正确的输出。

现在我的问题来了。我对它引用(?)类的方式做了一些修改,在这种情况下,我在符号属性中导出类就像这样。现在,代码将不起作用,我已经尝试解决这个问题大约5个小时了,我似乎无法完成它。

这是我在符号属性中添加类的图像:

这是我的login课程:

package {

    /*
        always extend a class using movieclip instead of sprite when using flash.
    */

    import flash.display.MovieClip;
    import flash.events.*;
    import flash.net.*;
    import flash.text.*;

    /*
        create our class
    */

    public class login extends MovieClip {

        public function login(): void {

            /*
                buttonMode gives the submit button a rollover
            */

            login_button.buttonMode = true;

            /*
                what this says is that when our button is pressed, the checkLogin function will run
            */

            login_button.addEventListener(MouseEvent.MOUSE_DOWN, checkLogin);

            /*
                set the initial textfield values
            */

            username.text = "";
            password.text = "";

        }

        public function checkLogin(e: MouseEvent): void {

            /*
                check fields before sending request to php
            */

            if (username.text == "" || password.text == "") {

                /*
                    if username or password fields are empty set error messages
                */

                if (username.text == "") {
                    username.text = "Enter your username";
                    trace(success);
                }

                if (password.text == "") {
                    password.text = "Enter your password";
                }

            } else {

                /*
                    init function to process login
                */
                processLogin();

            }

        }

        public function processLogin(): void {

            /*
                variables that we send to the php file
            */

            var phpVars: URLVariables = new URLVariables();

            /*
                we create a URLRequest  variable. This gets the php file path.
            */

            var phpFileRequest: URLRequest = new URLRequest("php/controlpanel.php");

            /*
                this allows us to use the post function in php
            */

            phpFileRequest.method = URLRequestMethod.POST;

            /*
                attach the php variables to the URLRequest
            */

            phpFileRequest.data = phpVars;

            /*
                create a new loader to load and send our urlrequest
            */

            var phpLoader: URLLoader = new URLLoader();
            phpLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
            phpLoader.addEventListener(Event.COMPLETE, showResult);

            /*
                now lets create the variables to send to the php file
            */

            phpVars.systemCall = "checkLogin";
            phpVars.username = username.text;
            phpVars.password = password.text;

            /*
                this will start the communication between flash and php
            */

            phpLoader.load(phpFileRequest);

        }

        public function showResult(event: Event): void {

            /*

                this autosizes the text field

                ***** You will need to import flash's text classes. You can do this by adding: 

                import flash.text.*;

                ...to your list of import statements 

            */

            result_text.autoSize = TextFieldAutoSize.LEFT;

            /*
                this gets the output and displays it in the result text field
            */

            result_text.text = "" + event.target.data.systemResult;
            trace(success);

        }
    }
}

修改:

以下是基类消失的图片:

感谢您的帮助。

0 个答案:

没有答案