Send Free SMS with Flex
Download source code: Free SMS with Flex Download
Live demo: http://www.freebiesms.co.uk/apps/flex/freebiesmsflex.html
Sending SMS using the FreebieSMS webservice is easy using Flex / Actionscript (Adobe Flash), and here's how.
First, define your MXML file as follows:
<my:FreebieSMS xmlns:my="*"
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:Label x="10" y="10" text="From Name"/>
<mx:TextInput x="100" y="10" id="tiFromName"/>
<mx:Label x="10" y="30" text="From Number"/>
<mx:TextInput x="100" y="30" text="00447" id="tiFromNumber"/>
<mx:Label x="10" y="50" text="To Name"/>
<mx:TextInput x="100" y="50" text="" id="tiToName"/>
<mx:Label x="10" y="70" text="To Number"/>
<mx:TextInput x="100" y="70" text="00447" id="tiToNumber"/>
<mx:Label x="10" y="90" text="Message"/>
<mx:TextArea x="100" y="90" id="taMessage"/>
<mx:Button x="100" y="150" label="Send SMS" click="click(event)"/>
<mx:WebService id="webService"
wsdl="http://www.freebiesms.co.uk/sendSMS.asmx?wsdl">
<mx:operation name="SendSms"
resultFormat="object"
result="SendSms_result(event);"
fault="SendSms_fault(event);" />
</mx:WebService>
</my:FreebieSMS>
This then uses a code-behind AS file like this:
package
{
import flash.events.Event;
import flash.events.MouseEvent;
import mx.controls.Alert;
import mx.core.Application;
import mx.rpc.soap.mxml.WebService;
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
import mx.controls.TextInput;
import mx.controls.TextArea;
public class FreebieSMS extends Application
{
public var webService:WebService;
public var tiFromName:TextInput;
public var tiFromNumber:TextInput;
public var tiToName:TextInput;
public var tiToNumber:TextInput;
public var taMessage:TextArea;
protected function click(event:MouseEvent)
{
/*
<SendSms xmlns="http://FreebieSMS.co.uk">
<FromName>string</FromName>
<FromNumber>string</FromNumber>
<ToNumber>string</ToNumber>
<Message>string</Message>
<locale>string</locale>
</SendSms>
*/
webService.SendSms(
tiFromName.text,
tiFromNumber.text,
tiToNumber.text,
taMessage.text,
"en-GB"
)
}
protected function SendSms_result(evt:ResultEvent):void
{
Alert.show("SMS Sent!");
}
protected function SendSms_fault(evt:FaultEvent):void
{
Alert.show(evt.type);
}
}
}
Note that this webservice can be accessed outside the server, with a flexible CrossDomain policy.
<cross-domain-policy>
<allow-access-from domain="*"/>
<allow-http-request-headers-from domain="*" headers="SOAPAction"/>
</cross-domain-policy>