Chapter 16. Browser Communication

In many cases, you may find it necessary to communicate with the browser that contains your application. Browser communication enables you to build applications that go beyond Flex itself; you can link to existing sites, communicate with other applications via JavaScript, and interact with the browser’s history, as a start. The ExternalInterface class lets you call out to the browser in which the application is running, get information about the containing HTML page, and call JavaScript methods, as well as letting JavaScript methods call into the Flex application. This chapter focuses on the functionality contained within the core Flex Framework, though there are other tools to assist with integration of the browser and the Flash Player.

Problem

You need to navigate to a separate URL.

Solution

Use the navigateToURL() method to navigate the browser to the new URL.

Discussion

The navigateToURL() method enables you to navigate the browser to a new URL in either the same window, a new window, or a specific window frame. This is one of the most common communications with the browser from a Flex application. To invoke the navigateToURL() method from within your Flex 4 application, use this approach:

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/halo"> <mx:Script> <![CDATA[ import flash.net.navigateToURL; private function goToURL() : void { ...

Get Flex 4 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.