O'Reilly logo

Programming Flex 2 by Joey Lott, Chafic Kazoun

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

Communicating with the Host Application

Flex applications require the Flash Player runtime environment to work. For this reason, it is common to think of Flex applications as being confined to Flash Player. However, it is entirely possible for a Flex application to communicate with the host application. For example, if a Flex application is running within a web browser, the application can interact with the browser. If a Flex application is running within a desktop executable, it can interact with that executable. This allows you to create integrated applications that span beyond the Flash Player context.

Flex application/host application communication takes place via a Flash Player class called flash.external.ExternalInterface. ExternalInterface allows you to make synchronous calls to host application methods from the Flex application, and from the host application to Flex application methods. ExternalInterface is quite simple to work with, and in most cases, it is quite appropriate.

Working with ExternalInterface

The flash.external.ExternalInterface class defines two static methods, named call( ) and addCallback( ), enabling Flex-to-host-application communication and host-application-to-Flex communication, respectively.

The call( ) method allows you to call a method of the host application by passing it the name of the method. If the host application method expects parameters, you can pass those parameters to the call( ) method following the name of the host application method. For ...

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