问题
I use this code but after publish when I open my file automatically 2 internet browser (www.example.com) are open
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);
}
}
}
I want, when I press my button then inter browser (www.example.com) should be open
回答1:
if you want to navigate to URL when the button is clicked you code should something like this:
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);
}
}
}
You can't use navigateToURL function in the constructor
回答2:
As far as I understand your problem :
You don't want the browsers to be already open but on click of some button.
If that is the case, Currently navigateToURL(request);
is in the constructor of bAEForm class.
Move it into a click event, Something like this :
myButton.addEventListener(MouseEvent.MOUSE_CLICK,
function(e) { navigateToURL(request); }, false,0,true);
where myButton is the button instance on click of which you want the browser to open.
来源:https://stackoverflow.com/questions/14042593/how-to-use-geturl-in-the-class-as3