Adobe
Products
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
Student and Teacher Editions
More products
Solutions
Creative tools for business
Digital marketing
Digital media
Education
Financial services
Government
Web Experience Management
More solutions
Learning Help Downloads Company
Buy
Home use for personal and home office
Education for students, educators, and staff
Business for small and medium businesses
Licensing programs for businesses, schools, and government
Special offers
Search
 
Info Sign in
Welcome,
My cart
My orders My Adobe
My Adobe
My orders
My information
My preferences
My products and services
Sign out
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out My orders My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Review and Checkout
Adobe Developer Connection / Flex Developer Center / Flex Test Drive for Mobile /

Flex Test Drive for Mobile: Add application functionality

by Adobe

Adobe logo

Modified

2 May 2011

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
Flash Builder Flex mobile

Video | Code | Tutorial | Links

Email, text, and call

 

This content requires Flash To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player. To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.

Download the complete sample code (ZIP, 14.8 MB)

Code

DetailView.mxml

<?xml version="1.0" encoding="utf-8"?> <s:View …> <fx:Script> <![CDATA[ (…) import flash.net.navigateToURL; protected function emailIcon_clickHandler(event:MouseEvent):void { navigateToURL(new URLRequest("mailto:"+getEmployeesByIDResult.lastResult.email)); } protected function textIcon_clickHandler(event:MouseEvent):void { navigateToURL(new URLRequest("sms:"+getEmployeesByIDResult.lastResult.cellphone)); } protected function textIcon2_clickHandler(event:MouseEvent):void { navigateToURL(new URLRequest("sms:"+getEmployeesByIDResult.lastResult.officephone)); } protected function phoneIcon_clickHandler(event:MouseEvent):void { navigateToURL(new URLRequest("tel:"+getEmployeesByIDResult.lastResult.cellphone)); } protected function phoneIcon2_clickHandler(event:MouseEvent):void { navigateToURL(new URLRequest("tel:"+getEmployeesByIDResult.lastResult.officephone)); } ]]> </fx:Script> (…) <s:Scroller height="100%" width="100%"> <s:VGroup height="100%" width="100%" gap="10" paddingLeft="120"> <s:Label fontWeight="bold" paddingTop="10" text="Title"/> <s:Label text="{getEmployeesByIDResult.lastResult.title}"/> <s:Group width="100%"> <s:Label fontWeight="bold" paddingTop="10" text="Cell Phone"/> <s:HGroup right="5"> <s:Image id="phoneIcon" click="phoneIcon_clickHandler(event)"> <s:source> <s:MultiDPIBitmapSource source160dpi="@Embed('assets/phone160.png')" source240dpi="@Embed('assets/phone240.png')" source320dpi="@Embed('assets/phone320.png')"/> </s:source> </s:Image> <s:Image id="textIcon" click="textIcon_clickHandler(event)"> <s:source> <s:MultiDPIBitmapSource source160dpi="@Embed('assets/text160.png')" source240dpi="@Embed('assets/text240.png')" source320dpi="@Embed('assets/text320.png')"/> </s:source> </s:Image> </s:HGroup> </s:Group> <s:Label text="{getEmployeesByIDResult.lastResult.cellphone}"/> <s:Group width="100%"> <s:Label fontWeight="bold" paddingTop="10" text="Office Phone"/> <s:HGroup right="5"> <s:Image id="phoneIcon2" click="phoneIcon2_clickHandler(event)"> <s:source> <s:MultiDPIBitmapSource source160dpi="@Embed('assets/phone160.png')" source240dpi="@Embed('assets/phone240.png')" source320dpi="@Embed('assets/phone320.png')"/> </s:source> </s:Image> <s:Image id="textIcon2" click="textIcon2_clickHandler(event)"> <s:source> <s:MultiDPIBitmapSource source160dpi="@Embed('assets/text160.png')" source240dpi="@Embed('assets/text240.png')" source320dpi="@Embed('assets/text320.png')"/> </s:source> </s:Image> </s:HGroup> </s:Group> <s:Label text="{getEmployeesByIDResult.lastResult.officephone}"/> <s:Group width="100%"> <s:Label fontWeight="bold" paddingTop="10" text="Email"/> <s:Image id="emailIcon" right="5" top="0" click="emailIcon_clickHandler(event)"> <s:source> <s:MultiDPIBitmapSource source160dpi="@Embed('assets/email160.png')" source240dpi="@Embed('assets/email240.png')" source320dpi="@Embed('assets/email320.png')"/> </s:source> </s:Image> </s:Group> <s:Label text="{getEmployeesByIDResult.lastResult.email}"/> <s:Label fontWeight="bold" paddingTop="10" text="Office"/> <s:Label text="{getEmployeesByIDResult.lastResult.office}"/> </s:VGroup> </s:Scroller> </s:View>

Tutorial

In Module 1, you retrieved data from a database and displayed it in a mobile application. In this module, you add application functionality. In this tutorial, you modify the DetailView, adding the ability to call employees and send them emails or texts. In the next tutorials, you modify the database: adding, updating, and deleting data.

Note: In the previous tutorial, Run on a device, you changed the project server settings (step 2) and the photo URLs (step 4) to reference your publicly available server. You should continue to use these settings so you can test sending emails and texts and making phone calls from the device in this tutorial.

Step 1: Add an email icon next to the email label.

In DetailView.mxml, place the Email Label component inside a Group container that has a height of 100%. Add an Image component to the Group and set its id to emailIcon , its right constraint to 5, its top constraint to 0, and its source property to a multiresolution bitmap using embedded assets, email160.jpg, email240.jpg, email320.jpg.

Add an email icon.
Figure 1. Add an email icon.

Step 2: Navigate to a mail URL when the email icon is clicked.

Generate a click handler for the emailIcon image. Inside the handler, call the navigateToURL() method and pass to it a new instance of the URLRequest object with a url property set to the string "" concatenated with the employee's email.

You use the navigateToURL() function in the flash.net package to make a request to the parent container, in this case, the device's operating system. In web and desktop applications, this function is typically used to open or replace browser windows (by passing a URL value). It can also be used to send emails (by passing a mailto link) in which case a mail program is opened to send an email. You can use the same syntax to send an email from a mobile application.

The navigateToURL() function has one required argument, an instance of the URLRequest class (see Figure 2).

View the arguments for the navigateToURL() function.
Figure 2. View the arguments for the navigateToURL() function.

The URLRequest constructor has one optional argument, a url string(see Figure 3).

View the arguments for the URLRequest constructor.
Figure 3. View the arguments for the URLRequest constructor.

Pass to the constructor a mailTo string with the selected employee's email. Your click handler for the email icon should appear as shown here:

protected function emailIcon_clickHandler(event:MouseEvent):void { navigateToURL(new URLRequest("mailto:"+getEmployeesByIDResult.lastResult.email)); }

Step 3: Send emails from the desktop simulator and your device.

Run the application in the desktop simulator, select an employee, and click the email icon. Repeat using your device.

On the desktop, you should see your mail program open (see Figure 4).

Send an email from the application using the desktop simulator.
Figure 4. Send an email from the application using the desktop simulator.

Run the application on your device, select an employee, and click the email icon (see Figure 5). Your email program should open for sending an email to the selected employee (see Figure 6).

See the email icon on the device.
Figure 5. See the email icon on the device.
Send an email from the application using your device.
Figure 6. Send an email from the application using your device.

Click the device's Back button to return to the application.

Step 4: Add phone and text messages icons next to the phone fields.

Place the Cell Phone Label component inside a Group container that has a height of 100%. Inside the Group after the Label, add an HGroup with a right constraint of 5. Add two Image controls to the HGroup. For the first, set its id to phoneIcon and its source property to a multiresolution bitmap using embedded assets, phone160.jpg, phone240.jpg, phone320.jpg. For the second, set its id to textIcon and its source property to a multiresolution bitmap using embedded assets, text160.jpg, text240.jpg, text320.jpg. Repeat for the Office Phone Label giving the images the id's textIcon2 and phoneIcon2 (see Figure 7).

Add phone and text icons.
Figure 7. Add phone and text icons.

Your code should appear as shown here:

<s:Group width="100%"> <s:Label fontWeight="bold" paddingTop="10" text="Cell Phone"/> <s:HGroup right="5"> <s:Image id="phoneIcon"> <s:source> <s:MultiDPIBitmapSource source160dpi="@Embed('assets/phone160.png')" source240dpi="@Embed('assets/phone240.png')" source320dpi="@Embed('assets/phone320.png')"/> </s:source> </s:Image> <s:Image id="textIcon"> <s:source> <s:MultiDPIBitmapSource source160dpi="@Embed('assets/text160.png')" source240dpi="@Embed('assets/text240.png')" source320dpi="@Embed('assets/text320.png')"/> </s:source> </s:Image> </s:HGroup> </s:Group> <s:Label text="{getEmployeesByIDResult.lastResult.cellphone}"/> <s:Group width="100%"> <s:Label fontWeight="bold" paddingTop="10" text="Office Phone"/> <s:HGroup right="5"> <s:Image id="phoneIcon2"> <s:source> <s:MultiDPIBitmapSource source160dpi="@Embed('assets/phone160.png')" source240dpi="@Embed('assets/phone240.png')" source320dpi="@Embed('assets/phone320.png')"/> </s:source> </s:Image> <s:Image id="textIcon2"> <s:source> <s:MultiDPIBitmapSource source160dpi="@Embed('assets/text160.png')" source240dpi="@Embed('assets/text240.png')" source320dpi="@Embed('assets/text320.png')"/> </s:source> </s:Image> </s:HGroup> </s:Group> <s:Label text="{getEmployeesByIDResult.lastResult.officephone}"/>

Step 5: Navigate to sms URLs when the text message icons are clicked.

Generate a click handler for the textIcon image. Inside the handler, call the navigateToURL() method and pass to it a new instance of the URLRequest object with a url property set to the string "sms:" concatenated with the employee's cell phone number.

Your click handlers for the text message icons should appear as shown here:

protected function textIcon_clickHandler(event:MouseEvent):void { navigateToURL(new URLRequest("sms:"+getEmployeesByIDResult.lastResult.cellphone)); } protected function textIcon2_clickHandler(event:MouseEvent):void { navigateToURL(new URLRequest("sms:"+getEmployeesByIDResult.lastResult.officephone)); }

Step 8: Send text messages from your device.

Run the application in the desktop simulator, select an employee, and click the text message icon. Repeat using your device.

On the desktop, you should see a message that the sms protocol is not associated with any program (unless yours is set up to!) (see Figure 8).

Try to send a text from the application using the desktop simulator.
Figure 8. Try to send a text from the application using the desktop simulator.

Run the application on your device, select an employee, and click the text message icon (see Figure 9). Your text message program should open for sending a text message to the selected employee (see Figure 10).

See the text message and phone icons on your device.
Figure 9. See the text message and phone icons on your device.
Send a text message from the application using your device.
Figure 10. Send a text message from the application using your device.

Click the device's Back button to return to the application.

Step 9: Navigate to tel URL's when the phone icons are clicked.

Generate a click handler for the phoneIcon and phoneIcon2 images. Inside the handlers, call the navigateToURL() method and pass to it a new instance of the URLRequest object with a url property set to the string "tel:" concatenated with the employee's phone number.

Your click handlers for the phone icons should appear as shown here:

protected function phoneIcon_clickHandler(event:MouseEvent):void { navigateToURL(new URLRequest("tel:"+getEmployeesByIDResult.lastResult.cellphone)); } protected function phoneIcon2_clickHandler(event:MouseEvent):void { navigateToURL(new URLRequest("tel:"+getEmployeesByIDResult.lastResult.officephone)); }

Step 10: Make calls from your device.

Run the application on your device, select an employee, and click phone.

Your phone program should open for calling the selected employee (see Figure 11).

Make a call from the application using your device.
Figure 11. Make a call from the application using your device.

Click the device's Back button to return to the application.

In this tutorial, you learned to make calls and send emails and text messages from your application. In the next tutorial, you add new employees to the database from the application.

Learn more

Refer to the following resources to learn more about this topic:

ActionScript 3 Reference

  • navigateToURL

Mobile and Devices Developer Center

 

Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License+Adobe Commercial Rights

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

More Like This

  • Flex Test Drive for Mobile: Add application functionality
  • Flex Test Drive for Mobile: Test and deploy your code
  • Flex Test Drive for Mobile: Deploy the application

Tutorials and samples

Tutorials

  • Flex mobile performance checklist
  • Flex and Maven with Flexmojos – Part 3: Journeyman
  • Migrating Flex 3 applications to Flex 4.5 – Part 4

Samples

  • Twitter Trends
  • Flex 4.5 reference applications
  • Mobile Trader Flex app on Android Market

Flex user forum

More
07/25/2011 Flash Player Debug Issues - Safari 5.1 & Chrome 13
04/22/2012 Loader png - wrong color values in BitmapData
04/22/2012 HTTPService and crossdomain.xml doesn't work as expected
04/23/2012 Memory related crashes in Flex application

Flex Cookbook

More
04/06/2012 How to detect screen resize with a SkinnableComponent
02/29/2012 Embed Stage3D content inside Flex application components
02/15/2012 Custom WorkFlow Component
02/09/2012 Using Camera with a MediaContainer instead of VideoDisplay

Products

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • Mobile Apps
  • Photoshop
  • Touch Apps
  • Student and Teacher Editions

Solutions

  • Digital marketing
  • Digital media
  • Web Experience Management

Industries

  • Education
  • Financial services
  • Government

Help

  • Product help centers
  • Orders and returns
  • Downloading and installing
  • My Adobe

Learning

  • Adobe Developer Connection
  • Adobe TV
  • Training and certification
  • Forums
  • Design Center

Ways to buy

  • For personal and home office
  • For students, educators, and staff
  • For small and medium businesses
  • For businesses, schools, and government
  • Special offers

Downloads

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy Policy and Cookies (Updated)

Ad Choices

Reviewed by TRUSTe: site privacy statement