Hey All,
Just recently started with AS3 and have hit a wall with the eventDispatcher and creating custom events. I can’t see what I am doing wrong:
My class file:
package resources.methodCalls{
import flash.display.*;
import flash.net.*;
import flash.events.*;
import flash.media.*;
public class requests {
public var requestedArray : Array = [];
// requests class constructor
public function requests() {
}
public function varCompiler(method:String, url:String, missionID:String, assignment:String, versionID:String) {
//establish opening and closing XML tags
var requestXML:XML =
<shuttleAPI>
<versionID>{versionID}</versionID>
<method>{method}</method>
<assignment>{assignment}</assignment>
<missionid>{missionID}</missionid>
</shuttleAPI>;
//appends interior tags to the recently established XML var
//requestXML.version = versionID;
//requestXML.method = method;
//requestXML.assignment = assignment;
//requestXML.missionid = missionID;
trace(requestXML.toXMLString());
methodRequest(method, url, requestXML);
}
private function dataHandler(event:Event):void {
var dataLoaded:URLLoader = URLLoader(event.target);
trace(dataLoaded.data);
var receivedXML:XML = new XML(dataLoaded.data);
trace("receivedXML = "+receivedXML);
trace("requestedArray ="+requestedArray);
for each (var list:XML in receivedXML.foo) {
trace( "items = "+list );
requestedArray.push(list);
trace( "requestedArray = "+requestedArray );
}
[COLOR=Red] dispatchEvent(new Event("dataLoaded"));[/COLOR]
}
public function methodRequest(method:String, url:String, requestXML:XML):void {
var dataRequest : URLRequest = new URLRequest (url);
var dataLoader : URLLoader = new URLLoader ();
var requestVars : URLVariables = new URLVariables ();
requestVars.xml = requestXML;
dataRequest.method = URLRequestMethod.POST;
dataRequest.data = requestVars;
dataLoader.addEventListener(Event.COMPLETE, dataHandler);
dataLoader.load(dataRequest);
}
}
}
The AS on the main timeline:
import resources.methodCalls.*;
var url:String = "http://##########";
var missionID:String = "1";
var assignment:String = "missionControl";
var versionID:String = "0.0.1";
var camRequest : Object = new requests();
camRequest.varCompiler("getCamList", url, missionID, assignment, versionID);
camRequest.addEventListener("dataLoaded", callbackHandler);
function callbackHandler(event: Event) {
trace("camRequest.requestedArray = "+camRequest.requestedArray);
}
Whenever I execute the code I get the following compiler error:
1180: Call to a possibly undefined method dispatchEvent.
Which is referring to the code I have highlighted in red in the class file.
What am I doing incorrectly?
Thank you for you time and energy.
Nate