Contact envelope



The Geolocation component uses the HTML5 API of modern browsers to retrieve the user's geographic location.


This component will NOT work within the AIR environment. For HTML support in AIR, try the native mx.controls.HTML and flash.html.HTMLLoader classes.


Only works if the browser supports HTML5 geolocation and ExternalInterface.

Flash Geolocation

Flash has both Geolocation and GeolocationEvent classes for mobile devices with location sensors. This class brings some of that functionality to desktop based applications.

Creating the HtmlGeolocation Component

The component is not visual and is not added to the display list. Extends EventDispatcher and should either be declared in the <fx:Declarations> tag or in Actionscript.

Using the HtmlGeolocation Component

Attach an UPDATE and ERROR listener and call getCurrentPosition() to retrieve the user location. Since the location data is returned asynchronously, an event handler is required to get the location data. See the events in the htmlGeolocation package for the information returned by the update and error events.


To test in the local domain, on the "preinitialize" event, add the following code to the "preinitialize" event handler:


Even with the above code, this component may fail in local testing in some browsers.

Note that users can deny access to their location if desired. Notice of rejection is available via the error event.


<htmlGeolocation:HtmlGeolocation  id="htmlGeolocation">
	error=", 'ERROR', 4, this, null, null, 0, 

See the HtmlGeolocation application for more example code.

Known Bugs

Firefox 4+: if the user does not allow location tracking by selecting "Not Now" to the permission prompt, it will not fire the errorHandler, so the developer will not get an indication of failure. Plan accordingly. May be a good idea to set a timeout handler.

Custom Events

Dispatched when the ExternalInterface returns position data after a call to getCurrentPosition().

Dispatched when the ExternalInterface returns an error after a call to getCurrentPosition().

Back To Top