Crap. Well, I got it from the example. Then just tried to change the small details to fit my php pages that I already have. I dont know how to script this stuff.
If there is anything I can copy and paste out there, I would sure love the info. I’ve been digging for 2 days and cant seem to get this right. I remember the days of Flash 4. Maybe there was alot less that could be done, but man… it was alot simpler then haha.
Sounds like you are trying to put two packages together. Like the error says, you can’t nest packages. Just pull out the elements you need from what I posted.
Try this out; I hacked this together in text edit, no idea if it has any errors.
Save this as “QueryDataBase.as”
package {
import flash.net.URLVariables;
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.net.URLRequest;
import flash.events.*;
public class QueryDataBase extends EventDispatcher {
private var php_Url:String;
private var phpResponse:String
//getter for accessing what php sends back to you. Note
//the return is typed as a string, you may want to change this
//to match what you get back from php!
public function getPhpResponse():String{
return phpResponse;
}
//constructor
public function QueryDataBase(php_Url:String) {
this.php_Url = php_Url;
requestPhpResponse()
}
//form up the php request
private function requestPhpResponse():void{
var myData:URLRequest = new URLRequest(php_Url);
myData.method = URLRequestMethod.GET;
var variables:URLVariables = new URLVariables();
myData.data = variables;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, dataOnLoad);
loader.addEventListener(IOErrorEvent.IO_ERROR, handleError);
loader.load(myData);
}
//listen for response from php
private function dataOnLoad(event:Event):void {
phpResponse = event.target.data;
//simply redispatch the complete event, so you can listen for success
//at the class instance level.
//As the events target will no longer be the loader, we populate our var
//that will hold the php response, and then access it via the getter
//in the complete event listener set up at the class level.
dispatchEvent(event);
}
private function handleError(event:IOErrorEvent):void {
throw new Error("There was an IOerror accessing the PHP file: ");
}
}
}
Then, in your main class, or on your timeline;
var getDataBaseData:QueryDataBase = new QueryDataBase("http://www.blysterband.com/bschedule/news.php");
getDataBaseData.addEventListener(Event.COMPLETE, callbackHandler);
var myDataBasesData:String
function callbackHandler(event:Event):void {
//we get a response from php, so we can access the returned data
//via our classes getter function
myDataBasesData = getDataBaseData.getPhpResponse
//do your stuff, you got data!
}
As I said, I have not tested this, but it should work…
I might have left something out when I was pasting it in the as or in the timeline. It put it all in one line so I tried to seperate it as it looked on here.
Once again, all the help is greatly appreciated.
Oh… I almost forgot. The link for News is the only one I have doing anything (inside the flash) so far.
what happens if you trace the event.target.data within the complete handler in the class, that way you can see if you are getting anything returned by php…
Wow, that is completely greek to me. Flash has realy gone and confused the hell out of me with all the changes. Well, thanks for the help, but it looks like this is a lost cause for me. I cant seem to grasp the concept of how to get this to work, and flash is WAY touchy these days. haha.