November 23, 2009

Send SMS to Mobile using Way2SMS webservice in Adobe Air

Hi,
I created one appication for send sms to mobile phones all over india. I use the way2sms service provider for send the message to mobile phone. Here i mention the code for send sms message to mobile phones.

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" backgroundColor="0xFFFFFF" width="500" height="380" showStatusBar="false"
layout="vertical" verticalGap="4" verticalScrollPolicy="off" horizontalScrollPolicy="off" creationComplete="onInit()" showTitleBar="false"
>
<mx:Script>
<![CDATA[
import mx.events.CloseEvent;
import mx.controls.Alert;
import flash.net.navigateToURL;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.events.ValidationResultEvent;
private var _dockImage:BitmapData;
private function onInit():void
{
var _loader:Loader = new Loader();
_loader.load(new URLRequest("images/systray_icon_16.png"));
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onImageLoaded);
}
private function onImageLoaded(evt:Event):void
{
_dockImage = evt.target.content.bitmapData;
}
private function onCloseApp(evt:Event):void
{
NativeApplication.nativeApplication.icon.bitmaps = [_dockImage];
}
public function onResponse(e:ResultEvent):void
{
if(e.result == "invalid login")
txt_status.text = e.result.toString();
else if(e.result == "done")
txt_status.text = "Message was send successfully";
else
txt_status.text = e.result.toString();
}
public function onFault(e:FaultEvent):void
{
txt_status.text = "Message was not send";
}
private function sendMsg():void
{
WS.getOperation('sendSMSToMany').send();
}
private function redirectPage():void
{
navigateToURL(new URLRequest("http://wwwa.way2sms.com/jsp/UserRegistration.jsp"),"_POST");
}
]]>
</mx:Script>
<mx:WebService id="WS" wsdl="http://www.aswinanand.com/sendsms.php?wsdl" showBusyCursor="true">
<mx:operation name="sendSMSToMany" result="onResponse(event)" fault="onFault(event)">
<mx:request>
<uid>
{txt_user.text}
</uid>
<pwd>
{txt_pwd.text}
</pwd>
<phone>
{txt_mobile.text}
</phone>
<msg>
{txt_msg.text}
</msg>
</mx:request>
</mx:operation>
</mx:WebService>
<mx:HBox verticalGap="1" horizontalGap="3" width="100%">
<mx:Image source="@Embed(source='images/logo.jpg')"/>
<mx:Text text="Send SMS to Friends in India" fontSize="18" fontWeight="bold"/>
</mx:HBox>
<mx:HBox verticalGap="1" width="100%" horizontalAlign="center">
<mx:Text id="txt_status" fontSize="16" fontWeight="bold" color="#FF0000"/>
</mx:HBox>
<mx:Form verticalGap="8" y="-30">
<mx:FormItem label="Username:" fontSize="14" color="#0000FF" fontWeight="bold" width="98%">
<mx:TextInput id="txt_user" fontSize="12" color="0x000000" fontWeight="normal" width="150" maxChars="10" restrict="0-9"/>
</mx:FormItem>
<mx:FormItem label="Password:" fontSize="14" color="#0000FF" fontWeight="bold" width="98%">
<mx:TextInput id="txt_pwd" fontSize="12" color="0x000000" fontWeight="normal" width="150" displayAsPassword="true"/>
</mx:FormItem>
<mx:FormItem label="Mobile NO:" fontSize="14" color="#0000FF" fontWeight="bold" width="98%">
<mx:TextInput id="txt_mobile" fontSize="12" color="0x000000" fontWeight="normal" width="150" maxChars="10" restrict="0-9"/>
</mx:FormItem>
<mx:FormItem label="Type Message:" fontSize="14" color="#0000FF" fontWeight="bold" width="98%">
<mx:TextArea id="txt_msg" fontSize="12" color="0x000000" fontWeight="normal" width="180" height="80" maxChars="140"
change="maxchar.text = '* maxchar 140('+txt_msg.text.length.toString()+')'"/>
<mx:Label id="maxchar" text="* maxchar 140(0)" fontSize="11" color="0xFF0000" fontWeight="normal"/>
</mx:FormItem>
<mx:FormItem width="100%" paddingTop="10">
<mx:HBox width="100%">
<mx:Button label="Send" click="sendMsg()"/>
<mx:Button label="Register Now" click="redirectPage()"/>
</mx:HBox>
</mx:FormItem>
</mx:Form>
</mx:WindowedApplication>

1 comment: