PDA

View Full Version : Sending variables to http without opening new window


Perception
05-25-2005, 01:21 PM
I currently developing an application to be able to use a third party service for SMS messaging, the code works but opens a browser window which I do not want to do, the app will run in the flash player only (this is for security as the app is only intended for local use not internet)

simplified:

I have a text input box (_level0.phone) where the phone number is to be entered and a button that sends the message.

the code behind the button is as follows (Passwords and secure info removed)

on (press) { // send sms text or flash message using http protocol
var user_name="User Name"; // Enter Server User Name
var password_account="Password"; // Enter Server Password
var text="Text to send"; //Message section
var msg_type="TEXT";
// the next line puts together the http header
var header_http='http://THIRDPARTYURL?user=' + user_name + '&passwd=' + password_account + "&text=" + text + "&msg_type=" + msg_type + "&sendto=" + _level0.phone ;
trace ("httpstring=" + header_http);
//getURL(header_http) // works correctly but opens new window
}

i have tried using LoadVars.sendAndLoad(header_http)
but get an error
The property being referenced does not have the static attribute.

I can send the SMS using getURL, but because the application will run only in flash player i do not want the browser window to open

any assistance greatly appreciated (Timescale)

Xeef
05-25-2005, 02:15 PM
hi and welcome to As.Org

For the following example, add a TextInput instance called name_ti, a TextArea instance called result_ta, and a Button instance called submit_button to the Stage. When the user clicks the Login button instance in the following example, two LoadVars objects are created: send_lv and result_lv. The send_lv object copies the name from the name_ti instance and sends the data to greeting.cfm. The result from this script loads into the result_lv object, and the server response displays in the TextArea instance (result_ta). Add the following ActionScript to Frame 1 of the Timeline:

var submitListener:Object = new Object();
submitListener.click = function(evt:Object) {
var result_lv:LoadVars = new LoadVars();
result_lv.onLoad = function(success:Boolean) {
if (success) {
result_ta.text = result_lv.welcomeMessage;
} else {
result_ta.text = "Error connecting to server.";
}
};
var send_lv:LoadVars = new LoadVars();
send_lv.name = name_ti.text;
send_lv.sendAndLoad("http://www.flash-mx.com/mm/greeting.cfm", result_lv, "POST");
};
submit_button.addEventListener("click", submitListener);

Perception
05-25-2005, 03:30 PM
Hi Xeef,

I tried your example as a new swf but having put some trace actions in, clicking the submit button does not do anything.

Xeef
05-25-2005, 03:51 PM
var result_lv:LoadVars = new LoadVars();
result_lv.onLoad = function(success:Boolean) {
if (success) {
trace(result_lv.welcomeMessage);
} else {
trace("Error connecting to server.");
}
};
var send_lv:LoadVars = new LoadVars();
send_lv.name = "Xeef"
send_lv.sendAndLoad("http://www.flash-mx.com/mm/greeting.cfm", result_lv, "POST");

output : "welcome Xeef"

P.S isn't my example it's from the help of MM

Perception
05-25-2005, 04:38 PM
Thanks Xeef,
This is giving me the same message as if I use (some progress at least) in my code as above

var send_lv:LoadVars=new LoadVars();

send_lv.sendAndLoad(header_http, send_lv, "GET")

gives me Error opening URL

I shall just keep plugging away

Perception
05-27-2005, 01:42 PM
Problem solved


on (press) { // send sms text or flash message using http protocol

// set up variables, reverse order to the required http string
sms_lv = new LoadVars();
sms_lv.from="Originator"
sms_lv.client_id="0000"
sms_lv.sendto=_level0.phone //text input area called phone
sms_lv.msg_type="TEXT";
sms_lv.text="SMS message to send"; //upto 160 chars
sms_lv.passwd="password"; // Enter Server Password
sms_lv.user="username"; // Enter Server User Name

//for debug set trace for sms_lv
trace(sms_lv)
//send it (works in explorer shell or flash player shell)
//it does not work if you test the movie
sms_lv.sendAndLoad(URL , sms_lv, "get");

}

Thanks to Xeef and CyanBlue for the code hits in this forum.

:eek: Beware this problem :eek:
The biggest problem occured due to the testing of the movie, when testing it in flash it did not work, as a final straw I exported it to run in a browser shell, strangely it worked, so then I thought I should try in flash player and bingo it worked

Excelent forum and resource site

Thanks
Perception :D

dananos
09-21-2009, 12:21 PM
In the example shown, is "THIRDPARTYURL" actually hosting the SWF file also?

If not, you'll probobly hit CrossDomain problems.