I have a UrlRequest in my Main Class, that does a request to a server in cakePHP, and its working fine, but when I do the exact same request in a click of a button its not working.
Can someone help me?
This is my code to do the request:
var token:String = LoaderInfo(root.loaderInfo).parameters.requestToken;
var myData:URLRequest = new URLRequest("users/personalInfo/"+token);
myData.method = URLRequestMethod.GET;
loader = new URLLoader(myData);
loader.addEventListener(Event.COMPLETE, onLoaded);
loader.dataFormat=URLLoaderDataFormat.TEXT;
loader.load(myData);
function onLoaded(e:Event):void {
MovieClip(this.root).gotoAndStop("main");
}
Click Handler
public function SaveProfileButton() {
addEventListener(MouseEvent.CLICK, mouseClick);
}
private function mouseClick(e:MouseEvent):void{
MovieClip(this.root).output.text = "loading...";
send();
}
send() is the code to do the request.
Thanks
I think you may need a cross domain policy xml on your server where the php is. 99% sure. http://www.adobe.com/devnet/articles/crossdomain_policy_file_spec.html
Related
I'm using the following code to check for updates in mysql database using flash as3 (actionscript 3.0).
The code will check the database using PHP on my server and will display the details in Flash application.
The issue that I have is that I am trying to run this code every 8 seconds but when I run the code and I trace(urlRequest); I get 100's of traces in less than 20 seconds!
I thought giving a setInterval(checkDataBase, 8000); will sort this issue out and will run the code every 8 seconds but I have no luck with this!
Could someone please advise on this issue?
This is my code:
addEventListener(Event.ENTER_FRAME,checkForNewOrder);
function checkForNewOrder (e:Event):void
{
checkDataBase();
}
/*
function we use to send the form
*/
function checkDataBase ():void
{
/*
we use the URLVariables class to store our php variables
*/
var phpVars:URLVariables = new URLVariables();
phpVars.result_textL = result_textL.text;
/*
we use the URLRequest method to get the address of our php file and attach the php vars.
*/
var urlRequest:URLRequest = new URLRequest("http://mywebsite.com/checkOrder.php");
trace(urlRequest);
/*
the POST method is used here so we can use php's $_POST function in order to recieve our php variables.
*/
urlRequest.method = URLRequestMethod.POST;
/*
this attaches our php variables to the url request
*/
urlRequest.data = phpVars;
/*
we use the URLLoader class to send the request URLVariables to the php file
*/
var urlLoader:URLLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
/*
runs the function once the php file has spoken to flash
*/
urlLoader.addEventListener(Event.COMPLETE, showResult);
/*
we send the request to the php file
*/
urlLoader.load(urlRequest);
}
setInterval(checkDataBase, 8000);
/*
function to show result
*/
function showResult (e:Event):void
{
orderDetails.text = "" + e.target.data.result_message;
if(orderDetails.text != "")
{
rejectBtn.y = 380.20;
}
}
addEventListener(Event.ENTER_FRAME,checkForNewOrder);
This causes your function to be called with the framerate you set up, so mabye 30 times per second.
setIntervall will add additional calls to the function. It does not override the enter frame.
Get rid of the enter frame register and you should be good to go.
I have been following a flash tutorial online and I have created a simple flash interface. I am trying to retrieve data from my SQL database via a PHP file and display. I get the following error when I compile:
Error #1009: Cannot access a property or method of a null object reference
var variables1:URLVariables = new URLVariables();
var varSend1:URLRequest = new URLRequest("databaseCall.php");
varSend1.method = URLRequestMethod.POST;
varSend1.data = variables1;
var varLoader1:URLLoader=new URLLoader();
varLoader1.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader1.addEventListener(Event.COMPLETE,completeHandler1);
variables1.comType = "requestEntries";
varLoader1.load(varSend1);
function completeHandler1(event:Event):void{
if(event.target.data.returnBody ==""){
gbOutput_txt.text = "No data coming through";
} else{
gbOutput_txt.condenseWhite = true;
gbOutput_txt.htmlText = "" +event.target.data.returnBody;
}
}
My code exactly matches the code that is used within the tutorial. I have modified the php file to simply return "" so the issue almost definitely lies within the action script...I think :S The compiler falls over when he completeHandler1 function is called. What do you think could be causing this?
Thanks in advance.
You need to declare the completeHandler1 function before you attempt to use it anywhere else.
Here is your code modified to describe what I am talking about.
var variables1:URLVariables = new URLVariables();
var varSend1:URLRequest = new URLRequest("databaseCall.php");
varSend1.method = URLRequestMethod.POST;
varSend1.data = variables1;
function completeHandler1(event:Event):void{
if(event.target.data.returnBody ==""){
gbOutput_txt.text = "No data coming through";
} else{
gbOutput_txt.condenseWhite = true;
gbOutput_txt.htmlText = "" +event.target.data.returnBody;
}
}
var varLoader1:URLLoader=new URLLoader();
varLoader1.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader1.addEventListener(Event.COMPLETE,completeHandler1);
variables1.comType = "requestEntries";
varLoader1.load(varSend1);
Give this a try and let me know if it works.
I have one problem..
I am making post request to php script. And I am getting back result as an xml. How can I make my qprogressbar working.
I have tried this:
v
oid MainWindow::init()
{
url = "http://127.0.0.1:8888/direkt_php_qt.php";
manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(updateDataTransferProgress(qint64,qint64)));
connect(manager, SIGNAL(finished(QNetworkReply*)),this, SLOT(replyFinished(QNetworkReply*)));
}
void MainWindow::updateDataTransferProgress(qint64 bytesReceived, qint64 bytesTotal)
{
ui->progressBar->setMaximum(bytesTotal + (bytesTotal * 0.25));
ui->progressBar->setValue(bytesReceived);
ui->progressBar->show();
}
But it's not working. I am getting error:
Object::connect: No such signal QNetworkAccessManager::downloadProgress(qint64,qint64)
How can I make this work with manager variable or something like that.
EDIT 2:
This is for example function that is calling init()
void MainWindow::Citanje_korisnika()
{
init();
QUrl params;
params.addQueryItem("action","Citanje_korisnika");
QByteArray data;
data.append(params.toString());
data.remove(0,1);
QNetworkRequest request;
request.setUrl(url);
request.setHeader(QNetworkRequest::ContentTypeHeader,
QVariant("application/x-www-form-urlencoded"));
reply = manager->post(request, data);
}
I tried your code but I always get unexpectedly out from program. Can you change me my function from which I am calling post method so it can work with init()
donwloadProgress is a signal of QNetworkReply.
Try something like this:
url = "http://127.0.0.1:8888/direkt_php_qt.php";
manager = new QNetworkAccessManager(this);
QNetworkReply* reply = manager->get(QNetworkRequest(url));
connect(reply, SIGNAL(downloadProgress(qint64, qint64)),this, SLOT(updateDataTransferProgress(qint64,qint64)));
I have values inside an XMLList in Actionscript. Need to send these values to the DB and update it.
My actionscript code is as follows:
public static function saveUserPermList():void {
var ht:HTTPService = new HTTPService();
ht.url = Config.getServerURL();
ht.method = URLRequestMethod.POST;
//ht.resultFormat = "e4x";
ht.contentType = "text/xml";
ht.request["action"] = "saveUserPermListXML";
ht.request["pdata"] = Application.application.userPermListModel.toString();
ht.addEventListener(ResultEvent.RESULT,AdminUserList.saveUserPermListResult);
ht.send();
}
public static function saveUserPermListResult(e:ResultEvent):void {
trace(e);
}
How can I send the XMLList data to PHP? Should I add a toString() to it?
Also what should be the contentType in Flex.
How can I catch this inside PHP, pl let me know, trying to use, this way,
if($user -> isAllowedAccess()) {
header("Content-type:text/xml");
$postedData = $_POST["pdata"];
// $xmldoc = simplexml_load_string($POST['pdata']);
// echo($xmldoc);
}
No luck. Pl let me know.
The method property of HTTPService should probably be "POST", and the contentType for the request itself should probably be "application/x-www-form-urlencoded".
On the PHP side, $_POST["pdata"] would then be a string containing XML markup. You could either save that in a database directly, or first parse it into XML (via SimpleXML or DOMDocument) and do something with the contained data.
PS: I've just found this answer that seems to shed some light on the internal behavior of the HTTPService class.
I'm using Actionscript 2.0 in combination with PHP, now I can make a call to my PHP file and receive data but apparently I have to use that data immediately, I cannot use it to fill my class variables.
This is what I want :
class user {
var lastname:String;
function user(in_ID:Number){
var ontvang:LoadVars = new LoadVars();
var zend:LoadVars = new LoadVars();
zend.ID = in_ID;
zend.sendAndLoad("http://localhost/Services/getUser.php", ontvang, "POST");
ontvang.onLoad = function(success:Boolean) {
if (success) {
lastname = ontvang.lastname;
} else {
lastname = 'error';
}
};
}
}
I've found out that this is a big issue in AS2, I found this post to work around it if you're loading XML data but I can't seem to get it to work with LoadVars :
http://www.actionscript.org/forums/showthread.php3?t=144046
Any help would be appreciated ..
When your onLoad handler is called, it is being called as if it were a member function of the LoadVars instance, and not your user instance.
There are several ways around this, one is to use Delegate.create() to create a function which will work as intended, for example:
import mx.utils.Delegate;
class user {
var lastname:String;
var ontvang:LoadVars;
function user(in_ID:Number){
ontvang = new LoadVars();
var zend:LoadVars = new LoadVars();
zend.ID = in_ID;
ontvang.onLoad = Delegate.create(this, onLoad);
zend.sendAndLoad("http://localhost/Services/getUser.php", ontvang, "POST");
};
}
function onLoad(success:Boolean) : Void
{
if (success) {
lastname = ontvang.lastname;
} else {
lastname = 'error';
}
}
}
Don't forget that the load is asynchronous - when you create one of your user objects, the member variables won't be immediately available. What you may need to do is let your user object be capable of signaling its readiness much like LoadVars does, (e.g. with a callback function provided by the caller) so that your app is driven by by these asynchronous events.