http object problem
by Jonathan L Bjork · in iTorque 2D · 11/28/2010 (11:25 pm) · 2 replies
Does anyone have an example of an http object script that works on iTorque 2D? I had one working some time ago, but when I launched it again today - I found it is not returning an echo from the server at all. What I am trying to do is send a short variable to a php page via get or post. The php page will echo a value after performing some database actions, and then the torque app will display the echoed value into a text field.
Like I said, I had a script that worked once, but is no longer working, so I want to start over. If someone has a script that is working now on iTorque 2D, I would love to see it.
Like I said, I had a script that worked once, but is no longer working, so I want to start over. If someone has a script that is working now on iTorque 2D, I would love to see it.
#2
I have a button control that executes getLoadingTip as shown below:
////////////////connect to php page
function getLoadingTip()
{
if(isInternetAvailable()){
static_1.setText("Internet Available");
initNetwork();
if(!isObject(LoadingTipObject))
new HTTPObject(LoadingTipObject);
%nextvar=static_1.text;
static_1.setText(%nextvar @ ": object created.");
LoadingTipObject.get("www.randametals.com:80", "/gwomrpg/index.php");
} else {
static_1.setText("No internet.");
}
}
function LoadingTipObject::onLine(%this, %line)
{
static_1.setText("Line: ");
if(%line !$= ""){
static_1.setText(%line);
}
}
///////////////end connect to php page
static_1 is a GuiTextCtrl. When I push the button, Internet Available: object created appears in static_1 - thus, I am getting inside the if isInternetAvailable condition, and the object is being created - however, the onLine function is never triggered. Interestingly enough, when I hit the button again, I get No Internet in static_1 - which indicates that the internet available condition changes to negative after the original connection.
Is it possible that these results are a problem having to do with the ipad simulator I am testing on out of xcode, or am I doing something wrong with the code itself?
11/29/2010 (4:53 pm)
Thanks very much for the post. It does help. Unfortunately, it confirms that I was doing it basically right, and still it is not working. Here is my situation:I have a button control that executes getLoadingTip as shown below:
////////////////connect to php page
function getLoadingTip()
{
if(isInternetAvailable()){
static_1.setText("Internet Available");
initNetwork();
if(!isObject(LoadingTipObject))
new HTTPObject(LoadingTipObject);
%nextvar=static_1.text;
static_1.setText(%nextvar @ ": object created.");
LoadingTipObject.get("www.randametals.com:80", "/gwomrpg/index.php");
} else {
static_1.setText("No internet.");
}
}
function LoadingTipObject::onLine(%this, %line)
{
static_1.setText("Line: ");
if(%line !$= ""){
static_1.setText(%line);
}
}
///////////////end connect to php page
static_1 is a GuiTextCtrl. When I push the button, Internet Available: object created appears in static_1 - thus, I am getting inside the if isInternetAvailable condition, and the object is being created - however, the onLine function is never triggered. Interestingly enough, when I hit the button again, I get No Internet in static_1 - which indicates that the internet available condition changes to negative after the original connection.
Is it possible that these results are a problem having to do with the ipad simulator I am testing on out of xcode, or am I doing something wrong with the code itself?
Torque Owner Justin Mosiman
Opsive
function getLoadingTip() { if(isLiteVersion() || isUnverified()) return; if(isInternetAvailable()){ initNetwork(); if(!isObject(LoadingTipObject)) new HTTPObject(LoadingTipObject); LoadingTipObject.get("www.opsive.com:80", "/path/to/page.php"); } } function LoadingTipObject::onLine(%this, %line) { if(%line !$= ""){ // do what you need to do } }I hope that helps