Posted by: iwishiwaschucknorris on: January 26, 2009
As this little bit of project shakedown takes place, the complete flash file is finished for use to connect to the php script that will then run the whole play.
All I am trying to find out tonight is how easy it is to create a simple function to send some files and then bring them back.
So far this is what i have got:
package {
import flash.events.*
import flash.net.*;
public class SendAndLoad {
public function SendAndLoad(url:String, _vars:URLVariables):void {
//Sets the request as the URL that is inputted into the function
var request:URLRequest = new URLRequest(url);
var loader:URLLoader = new URLLoader();
//encodes the data when it comes back to come back as variables
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
//Vars is the variables that have come into the function
request.data = _vars;
//vars are then posted out via that method
request.method = URLRequestMethod.POST;
loader.addEventListener(Event.COMPLETE, handleComplete);
loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
loader.load(request);
}
private function handleComplete(event:Event):void {
var loader:URLLoader = URLLoader(event.target);
}
private function onIOError(event:IOErrorEvent):void {
trace(“Error loading URL.”);
}
}
}