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 / Adobe AIR Developer Center / AIR Quick Starts for ActionScript developers /

Using the StageWebView class

by Sunil Bhaskaran

Sunil Bhaskaran

Content

  • Creating a StageWebView
  • Managing browsing history
  • Handling StageWebView events
  • Where to go from here

Modified

10 October 2011

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
Adobe AIR Flash Builder Flash Professional mobile

Requirements

Prerequisite knowledge

Familiarity with ActionScript 3.

User level

Intermediate

Required products

  • Flash Builder (Download trial)
  • Flash Professional CS5 (Download trial)

Sample files

  • StageWebViewTest.zip
  • StageWebViewTest-android-apk.zip

The StageWebView class in Adobe AIR allows you to display HTML content inside mobile Adobe AIR applications. It uses the system web control provided by the mobile phone's operating system. Hence, the available features and rendering appearance may vary from phone to phone. The StageWebView class provides only limited interaction between ActionScript and the HTML content.

In this article, you will learn the following:

  • How to a create a StageWebView object
  • How to manage browsing history
  • How to handle StageWebView events

Creating a StageWebView

Use the following code to create a StageWebView object. This code creates an object of the StageWebView class and attaches it directly to the stage using the stage property of the StageWebView object. Note that StageWebView is not a display object that can be attached to a Flash display list. You can control the size of the rectangle in which the HTML content in a StageWebView displayed using the viewPort method.

public var webView:StageWebView = new StageWebView(); webView.stage = this.stage; webView.viewPort = new Rectangle( 0, 0, stage.stageWidth, stage.stageHeight);

Assume that you want to display a web page (for example, http://www.Google.com) in the StageWebView object when you click a button. You can add a button outside the StageWebView, add an event listener to it, and then call a function to set the location. For example, the following function, when executed, loads the Google web page in the StageWebView. The loadURL() method is used to load the URL in the WebView class.

public function goGoogle(event:MouseEvent):void { webView.loadURL("http://www.google.com"); }

Managing browsing history

After you start browsing the web page, the visited pages are stored in the browsing history. You can use the historyBack() method to move to the previous web page stored in the browsing history, if any. For example, using a mouse event listener associated with a button, you can call the function given below. The isHistoryBackEnabled property returns true if a previous page exists in the browsing history.

public function moveBack(event:MouseEvent):void { if(webView.isHistoryBackEnabled) { webView.historyBack(); } else { trace("No pages in the browsing history.") } }

Similarly, the historyForward method allows you to navigate to the next page in the browsing history. The webView.isHistoryForwardEnabled property returns true if there is a next page in the browsing history.

public function moveForward(event:MouseEvent):void { if(webView.isHistoryForwardEnabled) { webView.historyBack(); } else { trace("No pages in the browsing history.") } }

Handling StageWebView events

When you work with the StageWebView object, you may want to know when a new URL is loaded. Listen for the locationChange events to react to URL changes. The following code adds an event listener to the StageWebView object. The event listener dispatches the LocationChangeEvent.LOCATION_CHANGE event when the URL is loaded.

webView.addEventListener(LocationChangeEvent.LOCATION_CHANGE,getUpdate); public function getUpdate(event:LocationChangeEvent):void { trace("The location changed."); }

The event, LocationChangeEvent.LOCATION_CHANGING , signals that the StageWebView location is about to change. You can use the preventDefault() method of the dispatched event object to prevent this default behavior. The following code dispatches LocationChangeEvent.LOCATION_CHANGING whenever the location of the StageWebView object is about to change and prevents the loading of the new URL.

webView.addEventListener(LocationChangeEvent.LOCATION_CHANGING,getUpdate); public function getUpdate(event:LocationChangeEvent):void { event.preventDefault(); trace("The new URL is blocked."); }

Where to go from here

In this article, you learned about StageWebView and the events associated with it. For more information refer to the following resources:

  • ActionScript 3 Reference for Adobe Flash Platform
  • ActionScript 3 Developers Guide

More Like This

  • Capturing soft key input
  • Capturing video input in a mobile AIR application
  • Using the tel: and sms: URIs in a mobile phone application
  • Using the Adobe AIR Geolocation APIs on Android

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