0

我使用此代码,但在发布后,当我自动打开我的文件时,2 个互联网浏览器(www.example.com)已打开

package {

    import flash.display.SimpleButton;
    import flash.display.Sprite;
    import flash.net.navigateToURL;
    import flash.net.URLRequest;
    import flash.net.URLRequestMethod;
    import flash.net.URLVariables;

    public class bAEForm extends SimpleButton {

        public function bAEForm() {
            var url:String = "http://www.google.com";
            var request:URLRequest = new URLRequest(url);

            var variables:URLVariables = new URLVariables();
            variables.exampleSessionId = new Date().getTime();
            variables.exampleUserLabel = "guest";
            request.data = variables;
            request.method = URLRequestMethod.POST;

            navigateToURL(request);
        }
    }
}

我想,当我按下按钮时,应该打开浏览器间(www.example.com)

4

2 回答 2

0

据我了解您的问题:

您不希望浏览器已经打开,而是单击某个按钮。

如果是这种情况,CurrentlynavigateToURL(request);bAEForm类的构造函数中。

将其移动到点击事件中,如下所示:

myButton.addEventListener(MouseEvent.MOUSE_CLICK, 

          function(e) { navigateToURL(request); }, false,0,true);

其中myButton是您希望浏览器打开的单击按钮实例。

于 2012-12-26T16:06:22.857 回答
0

如果您想在单击按钮时导航到 URL,您的代码应该是这样的:

package {

    import flash.display.SimpleButton;
    import flash.display.Sprite;
    import flash.net.navigateToURL;
    import flash.net.URLRequest;
    import flash.net.URLRequestMethod;
    import flash.net.URLVariables;

    import flash.events.MouseEvent;

    public class bAEForm extends SimpleButton {

        public function bAEForm() {
            this.addEventListener(MouseEvent.CLICK, clickHandler);
        }

        private function clickHandler(event:MouseEvent)
        {
            var url:String = "http://www.google.com";
            var request:URLRequest = new URLRequest(url);

            var variables:URLVariables = new URLVariables();
            variables.exampleSessionId = new Date().getTime();
            variables.exampleUserLabel = "guest";
            request.data = variables;
            request.method = URLRequestMethod.POST;

            navigateToURL(request);
        }
    }
}

您不能在构造函数中使用 navigateToURL 函数

于 2012-12-26T16:08:28.147 回答