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 lets you 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 example, ...

Get Programming Flex 3 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.