Hello again!
Out of some curiosity and the use of possible standard key variables so I don’t have to create several instances to the same class, I was trying the following:
var urlRequest:URLRequest = new URLRequest(website + "/news_test.txt");
var urlLoader:URLLoader = new URLLoader();
var urlVars:URLVariables = new URLVariables();
urlRequest.method = URLRequestMethod.POST;
urlLoader.addEventListener(Event.COMPLETE, newsLoaded);
urlLoader.dataFormat=URLLoaderDataFormat.VARIABLES;
// First use of Request/Loader
function newsLoaded(event:Event):void {
trace(event.target.data.news);
event.currentTarget.removeEventListener(Event.COMPLETE,newsLoaded);
}
urlLoader.load(urlRequest);
// Second use
loginButton.addEventListener(MouseEvent.CLICK, loginOnClick, false, 0, true);
function loginOnClick(event:MouseEvent):void{
urlVars.u = usernameTextField.text;
urlVars.p = passwordTextField.text;
urlRequest = new URLRequest("validate.asp"); // Does not work.
urlRequest.data = urlVars;
urlLoader.load(urlRequest); // Does not work.
urlLoader.addEventListener(Event.COMPLETE, loginLoaded);
}
That approach gave me the following error:
Error:[Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs](http://www.visible-form.com/blog/error-2101-the-string-passed-to-urlvariablesdecode-must-be-a-url-encoded-query-string-containing-namevalue-pairs/)
at Error$/throwError()
at flash.net::URLVariables/decode()
at flash.net::URLVariables()
at flash.net::URLLoader/onComplete()
This error does not occur if I try the same thing but instead of reusing urlRequest and urlLoader I create new instances of the same classes.
**
My question is:**
Is there a better approach to this on AS3? Something tells me I’m just heading the wrong way there…