简体   繁体   中英

In as3 can an if statement run an event tracker or call a function?

I've come across some syntax I'm not familiar with and am unable to find any reference online.

In the below as3 function is the if statement calling the 'sendTrackingEvent' function? And in the 'sendTrackingEvent' function is the if statement sending the tracking event?

function trackingHandler(page: String)
{
    if (! sendTrackingEvent(EID,"Document View",page))
    {
        fl_SavePreferences_5(EID + ",Document View," + page);
    }

}



function sendTrackingEvent(category:String, action:String, label:String):Boolean
{
    if (tracker.trackEvent(category,action,label))
    {

        return true;
    }
    else
    {

        return false;
    }
}

Thanks in advance for any help. I'm still learning.

sendTrackingEvent is a function that returns true or false

the first if statement is evaluating the RESPONSE (return value) of that function. So if sendTrackingEvent(EID,"Document View",page) returns false, then your if statement will run (since the ! means NOT true).

Same for the second if statement inside of sendTrackingEvent .

It's evaluating the return value of tracker.trackEvent(category,action,label) .


That function ( sendTrackingEvent ) could actually be simplified to this:

function sendTrackingEvent(category:String, action:String, label:String):Boolean
{
    return tracker.trackEvent(category,action,label);
}

And for that matter you don't even need the sendTrackingEvent function, as you could just do this:

function trackingHandler(page: String)
{
    if (! tracker.trackEvent(EID,"Document View",page))
    {
        fl_SavePreferences_5(EID + ",Document View," + page);
    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM