Avatar of JoachimPetersen
JoachimPetersen
Flag for Denmark asked on

Flex Mobile - check current view

Hello

I am having a problem, with something I don't understand why:

I have a timer that will start(timer will still run when you are on other view), I wan't the timer handler to only do something when I am on the current view:

if (navigator.activeView.className == 'TestView'){
                                          //function
}

It gives an null error when I change the view and the timer handler fires:
Cannot access a property or method of a null object reference.

Yes, I have a trace function in the init function on the other views that I change to and it gives a valid name back in the 'console', why does my if function give an null error when it is not == with the current view class name, I also now made a trace before the if statement, it seems that the timers current view is null on other views but not on the view that the timer started on?

Here is a demo project showing you the problem:
http://www.megafileupload.com/en/file/418802/TestCurr-fxp.html
Apache Flex

Avatar of undefined
Last Comment
Gary Benade

8/22/2022 - Mon
Gary Benade

Try wrapping the call in a callLater to delay it by 1 frame and give the navigator time to initailize:

callLater( function()
{
    if (navigator.activeView.className == 'TestView')
    {
          //function
    }
});
ASKER CERTIFIED SOLUTION
Gary Benade

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck