PDA

View Full Version : Getting my butt kicked: URLLoader errors.


djliquidice
08-15-2006, 03:15 PM
OK, so i downloaded the whole flexbuilder2 + sdk. I'm getting errors "Access of undfined property "request, loader and dataXML". This is pissing me off. This is coming right out of the programming_as3.pdf file (pg 367). I included a bunch of shyte to see if i was forgetting something.



import mx.controls.*;
import mx.rpc.http.*;

import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.*;
import flash.xml.*;
import flash.events.*;
import flash.errors.*;
var secondsUTC:Number = new Date().time;
var dataXML:XML = <login><time>{secondsUTC}</time><username>Ernie</username><password>guru</password></login>;
var request:URLRequest = new URLRequest("http://www.yourdomain.com/login.cfm");
request.contentType = "text/xml";
request.data = dataXML.toXMLString();
request.method = URLRequestMethod.POST;
var loader:URLLoader = new URLLoader();
try {
loader.load(request);
} catch (error:ArgumentError) {
trace("An ArgumentError has occurred.");
} catch (error:SecurityError) {
trace("A SecurityError has occurred.");
}

The previous snippet creates an XML instance named dataXml that contains an XML packet
to be sent to the server. Next, you set the URLRequest contentType property to "text/xml"
and set the URLRequest data property to the contents of the XML packet, which are
converted to a string by using the XML.toXMLString() method. Finally, you create a new
URLLoader instance and send the request to the remote script by using the
URLLoader.load() method.

senocular
08-15-2006, 03:34 PM
you should be putting all/most of that code within a method or the constructor

djliquidice
08-15-2006, 03:37 PM
Hi senocular,

I have encapsulated the data in the mx:script & CDATA tags. You're teling me that i should create a method/function to run this blocK?
Wow, the errors went away!

i noticed the way things are done in the AS world 99% of the stuff is function based. Interesting.


Thank you so much.