O'Reilly logo

Flex 4 Cookbook by Garth Braithwaite, Joshua Noble, Todd Anderson, Marco Casario, Rich Tretola

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 { ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required