Question

1120: Access of undefined property event. How to get this event /event.latitude.toString()/ to mail it

function onMapReady(e: Event): void {
if (Geolocation.isSupported) {
    var geo = new Geolocation();
    geo.setRequestedUpdateInterval(100);
    geo.addEventListener(GeolocationEvent.UPDATE, geolocationUpdateHandler);
}
}

function geolocationUpdateHandler(event: GeolocationEvent): void {
trace("lat:" + event.latitude.toString() + " - ");
trace("long:" + event.longitude.toString() + "° - ");
}

ve_btn.addEventListener(MouseEvent.CLICK, send);
function send(e: MouseEvent): void {
navigateToURL(new URLRequest("mailto:test@test.lv?body=</br>  latitude=" +  event.latitude.toString() + "</br>  longitude=" + event.longitude.toString()));
}
Was it helpful?

Solution

Alright, I'll try to explain this. If you want to use the longitude and latitude values from your Geolocation event when you click your mouse on something, you need to store those values somewhere because MouseEvent does not have those properties. Only GeolocationEvent has those.

How do you solve this then? simple, create variables that hold the latitude and longitude values that are retrieved in your geolocationUpdateHandler(...) method.

Sorta like this

var latitude:Number = 0;
var longitude:Number = 0;    

function onMapReady(e: Event): void {
    if (Geolocation.isSupported) {
        var geo = new Geolocation();
        geo.setRequestedUpdateInterval(100);
        geo.addEventListener(GeolocationEvent.UPDATE, geolocationUpdateHandler);
    }
    }

    function geolocationUpdateHandler(event: GeolocationEvent): void {
    trace("lat:" + event.latitude.toString() + " - ");
    trace("long:" + event.longitude.toString() + "° - ");
    latitude = event.latitude;
    longitude = event.longitude;
    }

    ve_btn.addEventListener(MouseEvent.CLICK, send);
    function send(e: MouseEvent): void {
    navigateToURL(new URLRequest("mailto:test@test.lv?body=</br>  latitude=" +  latitude.toString() + "</br>  longitude=" + longitude.toString()));
    }

OTHER TIPS

Change this part :

function send(e: MouseEvent): void 

to this:

function send(event: MouseEvent): void 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top