Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9244717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:06:15+00:00 2026-06-18T09:06:15+00:00

Im trying to get the toggle switch to DISABLE and STOP the geolocation routine…

  • 0

Im trying to get the toggle switch to DISABLE and STOP the geolocation routine…

i get null object error when geo is set to new Geolocation — what am I missing here?

        private function gogeo():void
        {
            if (Geolocation.isSupported)
            {
                var geo:Geolocation = new Geolocation();
                geo.setRequestedUpdateInterval(2000);
                geo.addEventListener(GeolocationEvent.UPDATE, geolocationUpdateHandler);
            }
            else
            {
                trace("No geolocation support.");
            }   
        }



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

        }
        protected function toggleswitch1_changeHandler(event:Event):void
        {

            if (toggleswitch1.selected == false) {
            trace("The function should STOP"); 

            geo.removeEventListener(GeolocationEvent.UPDATE, geolocationUpdateHandler);
            geo = null;

        } else {
            trace("The function should RESTART");

            geo = new Geolocation();
            geo.addEventListener(GeolocationEvent.UPDATE, geolocationUpdateHandler);
        }
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:06:16+00:00Added an answer on June 18, 2026 at 9:06 am

    Define geo outside of the function:

    private var geo:GeoLocation;
    
    private function gogeo():void
    {
        if (Geolocation.isSupported)
        {
            geo = new Geolocation();
            geo.setRequestedUpdateInterval(2000);
            geo.addEventListener(GeolocationEvent.UPDATE, geolocationUpdateHandler);
        }
        else
        {
            trace("No geolocation support.");
        }   
    }
    

    variables are only available within their ‘scope’ – eg: if you define a variable inside a function, it is only available from within that function

    edit:

    To define geo as global:

    In top level of your app (ie in the main mxml file), add a public declaration:

    public var geo:GeoLocation;
    

    And then access it from anywhere in your app using:

    (FlexGlobals.topLevelApplication as MyAppClass).geo
    

    instead of just “geo”; where MyAppClass is the name of your app (ie: the name of your main mxml class)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get a recursive fadeIn , show or toggle function to work
I am trying to get jQuery to animate with slide rather than toggle. I
I'm trying to get a toggle effect but not quite sure how to do
I'm trying to get #content to toggle, but it won't work. $(button).click(function () {
I am trying to get a wxPython TimeCtrl widget to toggle it's value 12hr
I've been trying to get this arrow toggle script work on my page. I
I'm trying to get the Toggle Tab to slide with the content, I currently
I'm trying to get both a fadeIn (opacity toggle) and border fade (using jquery-animate-colors
I am trying to get the value from a twitter-bootstrap data-toggle=buttons-radio submitted, along with
I'm trying to get the following jquery toggle to work on IE, FF, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.