Mobile SMS Using ActionScript 3.0
Submitted by rinvizle on Wednesday, February 8, 2017 - 11:20.
In this tutorial we will create a Mobile SMS Application in ActionScript 3.0. This application is very useful for the android developers, the application create a message from the field and generate a group of contacts using drop-down from the database. This Mobile SMS application relies to the users mobile data to access or to send a message in every contacts. And it is compose of smsane file extension to send a message from the contacts.
For The Group of contacts we use a Dropdown Function To get the data.
The Text Field Function.
The Button Function to send and generate a message.
And For the Mediator of the SMSANE extension function to enable and access the data of the mobile phone.
Hope that you learn in this tutorial. And for more updates and programming tutorials don't hesitate to ask and we will answer your questions and suggestions. Don't forget to LIKE & SHARE this website.
Sample Code
The UI Form Function.- package views
- {
- import commons.Manager;
- import commons.ScreenManager;
- import events.ClassEvent;
- import flash.events.MouseEvent;
- import flash.text.TextFormatAlign;
- import flash.text.engine.FontWeight;
- import flashx.textLayout.formats.VerticalAlign;
- import models.vo.CClass;
- import mx.collections.ArrayList;
- import org.osmf.layout.HorizontalAlign;
- import spark.components.Button;
- import spark.components.DropDownList;
- import spark.components.HGroup;
- import spark.components.Label;
- import spark.components.TextArea;
- import spark.components.VGroup;
- import spark.components.View;
- import spark.events.DropDownEvent;
- import spark.events.TextOperationEvent;
- public class SMSView extends View
- {
- protected var mainContent:VGroup;
- protected const SCALE:Number = ScreenManager.scale;
- private const LABEL_FONT_SIZE:Number = 32 * SCALE;
- private var titleLabel:Label;
- private var mainMenuButton:Button;
- private var actionButton:Button;
- private var textarea:TextArea;
- private var btnSend:Button;
- private var classesDropwDown:DropDownList;
- public function SMSView()
- {
- super();
- titleLabel = new Label();
- titleLabel.percentWidth = 100;
- titleLabel.setStyle("fontSize", 32 * SCALE);
- titleLabel.setStyle("color", 0xFFFFFF);
- titleLabel.setStyle("textAlign", TextFormatAlign.CENTER);
- titleLabel.setStyle("fontFamily", "Arial");
- titleLabel.setStyle("fontWeight", FontWeight.BOLD);
- titleLabel.text = "SMS";
- var myHGrp:HGroup = new HGroup();
- myHGrp.verticalAlign = VerticalAlign.MIDDLE;
- myHGrp.horizontalAlign = HorizontalAlign.RIGHT;
- myHGrp.percentWidth = 100;
- myHGrp.height = headerHeight;
- myHGrp.maxHeight = headerHeight;
- myHGrp.gap = 20 * SCALE;
- myHGrp.addElement(titleLabel);
- titleContent.push(myHGrp);
- actionButton = new Button();
- actionButton.width = headerHeight;
- actionButton.height = headerHeight;
- actionButton.visible = false;
- actionContent.push(actionButton);
- mainContent = new VGroup();
- mainContent.paddingTop = 20 * SCALE;
- mainContent.paddingRight = 20 * SCALE;
- mainContent.paddingLeft = 20 * SCALE;
- mainContent.paddingBottom = 20 * SCALE;
- mainContent.percentWidth = 100;
- mainContent.percentHeight = 100;
- mainContent.horizontalAlign = HorizontalAlign.CENTER;
- mainContent.gap = 10 * SCALE;
- this.addElement(mainContent);
- textarea = new TextArea();
- textarea.percentWidth = 100;
- textarea.height = 550 * SCALE;
- textarea.setStyle("fontSize", 35 * SCALE);
- textarea.addEventListener(TextOperationEvent.CHANGE, onChangeText);
- mainContent.addElement(textarea);
- classesDropwDown = new DropDownList();
- classesDropwDown.percentWidth = 100;
- classesDropwDown.height = 70 * SCALE;
- classesDropwDown.selectedIndex = 0;
- classesDropwDown.setStyle("borderColor",0xdddddd);
- classesDropwDown.setStyle("dropShadowVisible",false);
- classesDropwDown.setStyle("editable",false);
- classesDropwDown.setStyle("fontSize", LABEL_FONT_SIZE);
- classesDropwDown.buttonMode = true;
- classesDropwDown.addEventListener(DropDownEvent.CLOSE, onSelectClass);
- classesDropwDown.addEventListener(MouseEvent.CLICK, onClickDropwDown);
- mainContent.addElement(classesDropwDown);
- btnSend = new Button();
- btnSend.label = "Send";
- btnSend.enabled = false;
- btnSend.percentWidth = 100;
- btnSend.height = 70 * SCALE;
- btnSend.setStyle("fontSize", 35 * SCALE);
- btnSend.addEventListener(MouseEvent.CLICK, onSendSMS);
- mainContent.addElement(btnSend);
- }
- }
- }
- private function onClickDropwDown(event:MouseEvent):void
- {
- DropDownList(event.currentTarget).openDropDown();
- }
- private function onSelectClass(event:DropDownEvent):void
- {
- if(DropDownList(event.target).selectedItem)
- {
- if(!Manager.isTextEmpty(textarea.text) && int(DropDownList(event.target).selectedItem.data) > 0)
- {
- btnSend.enabled = true;
- }
- else
- {
- btnSend.enabled = false;
- }
- }
- }
- {
- _classes = value;
- if(_classes != null && _classes.length)
- {
- var classesLists:ArrayList = new ArrayList();
- for (var i:int = 0; i < _classes.length; i++)
- {
- var cclass:CClass = CClass(_classes[i]);
- classesLists.addItem({label: cclass.className, data: cclass.id});
- }
- classesDropwDown.dataProvider = classesLists;
- textarea.enabled = true;
- classesDropwDown.enabled = true;
- }
- else
- {
- textarea.enabled = false;
- classesDropwDown.enabled = false;
- }
- }
- public function get smsText():String
- {
- return textarea.text;
- }
- public function clearSmsText():void
- {
- textarea.text = "";
- }
- private function onSendSMS(event:MouseEvent):void
- {
- var selectedClass:CClass = new CClass();
- for (var i:int = 0; i < _classes.length; i++)
- var cclass:CClass = CClass(_classes[i]);
- if(cclass.id == int(classesDropwDown.selectedItem.data))
- {
- selectedClass = cclass;
- break;
- }
- }
- dispatchEvent(new ClassEvent(ClassEvent.SEND_SMS,selectedClass));
- }
- package mediators
- {
- import com.sms.ane.SmsAne;
- import commons.Manager;
- import events.ClassEvent;
- import models.ClassModel;
- import models.vo.Student;
- import org.robotlegs.mvcs.Mediator;
- import views.SMSView;
- public class SMSViewMediator extends Mediator
- {
- [Inject] public var view:SMSView;
- [Inject] public var classModel:ClassModel;
- public function SMSViewMediator()
- {
- }
- override public function onRegister():void
- {
- eventMap.mapListener(view, ClassEvent.SEND_SMS, onSendSMS);
- init();
- }
- private function init():void
- {
- classModel.getAllClasses();
- view.classes = classModel.classes;
- }
- private function onSendSMS(event:ClassEvent):void
- {
- classModel.selectedClass = event.cclass;
- classModel.getAllClassStudents();
- {
- if(!Manager.isTextEmpty(student.cellnumber))
- {
- try
- {
- if(student.cellnumber.length == 10 || student.cellnumber.length == 11)
- {
- var cellNumber:String = (student.cellnumber.length == 10) ? String("0" + student.cellnumber.length) : student.cellnumber;
- SmsAne.getInstance().sendSMS(cellNumber, view.smsText);
- }
- }
- catch(e:Error)
- {
- trace("");
- }
- }
- }
- }
- }
- }
Add new comment
- 34 views