Question about Protection API

Eddie, can you please answer this.

I don’t understand, on the second frame of the timeline (right after the preloader) I have this code:

if (idi.idnet != null)
{
if(idi.idnet._protection.isBlacklisted() == true);
{
//show movieclip
}
}

For some reason it returns true. What is the good way of doing this check?
I also have a similar code in the IDI.as file:

if( idnet.type == ‘protection’)
{
if(idnet._protection.isBlacklisted() == true)
{
//show movieclip
}
}

Please let me know what I’m doing wrong.

Thanks.
Ankit.

1 Like

Hi,

The problem could be that the list is not loaded yet. Although, it should return false by default, so maybe I’m missing something.

Try this

private function handleIDNET(e:Event) {
    if( idnet.type == 'protection'){
        if(idnet._protection.isBlacklisted()){
            // Show movie clip and disable game
        }
    }
}

Note handleIDNET above, this will trigger once the list is loaded. More general info is available via the AS3 protection docs.

That’s what I did before, but it always returned false. Could it be because my classes are set to “Export on frame 2”? (if I don’t do that, my preloader doesn’t work well) Then maybe I should only add the IDI object to the stage on frame 2?

Hi Snails,

You can load the id.net SDK later. Of course it’s better to load it early in some cases.

The main point with Protection is to wait for idnet.type == ‘protection’ and then check isBlacklisted(). You can store it or have some action happen once received.

I have similar problem, but with isSponsor() method. Here is my function for handling idi event

if( idnet.type == ‘protection’){
_isGameOnSponsorSite = idnet._protection.isSponsor();
stage.dispatchEvent(new IdiEvent(IdiEvent.SHOW_MAIN_MENU));
}

Here I set _isGameOnSponsor site, which tells mainMenu to show/hide ‘more games’ button depending on whether the game is on sponsor site or not. Then I dispatch event telling the main menu to show. When I run it locally the idnet event with type == ‘protection’ is fired and everything works fine, but when I uploaded it to my server to test it, it seems that the first time game is loaded this event is not fired and the main menu doesnt show, but if I hit refresh then it seems like the event is fired and main menu shows. Anyone could help? I was trying different approaches, but if I don’t wait for this event I couldn’t know if to show or not the more games button.

I forgot to mention, I am loading the SDK in my preloader class, before everything else.

I noticed a small typo in your code. The protection var needs an underscore like so.

idnet._protection.isSponsor()

If that doesn’t do it, it could be a timing issue but it seems like your event would handle that.

Check those things first. If it still have problems, you can post or PM me a link and I can look at the traces, maybe it gives a clue.

Here is a link to the game:
http://pro-game.comyr.com/FishAndDestroy3/FishAndDestroy3.html

The typo was made when I paste my code, it is with underscore in the game code. If you load the game you’ll see the first time when the game is load the main menu won’t appear, but if then you refresh the page everything is working.

Now I see that in my log I have this error:
Protection: unable to access page scripts Error: Error #2067: The ExternalInterface is not available in this container. ExternalInterface requires Internet Explorer ActiveX, Firefox, Mozilla 1.

right after the log - ‘‘IDNET: game api initialized’’, so I tried to open the game with IE and it seems to work. Any thoughts?

That error is expected. It only means allowscriptaccess is not turned on in the embed code.

I tested the game and the links work as expected. Still need to test on y8 of course.

One problem I saw is on firefox, the game seems to get stuck on the loading screen at 100%.

Yes, this is what I ment in the first place. I am showing the main menu after preloader on recieving event with idnet.type == ‘protection’, but it doesn’t seem to fire when the game is first loaded, but if you try and hit refresh then it will work. I am not sure, but I think this is some problem with the API.

That sounds like a race condition. Is the game waiting for the protection event? If so, the sequence may not always work as expected. For example, your code that is waiting for the event might not be loaded yet. In Firefox the game never loads for me.

Ohh I feel stupid :slight_smile:
Yes this was the problem, the class that is waiting for the event is not yet loaded and that is why when hitting refresh it worked.
So what I am now doing, in case someone has similar problem, is to set a boolean var that holds if the protection event was handled and in my game flow class I check if the protection was set, if so I show main menu else I add listener for event whitch I dispatch on handling protection.

Thanks for the help eddie :slight_smile:

1 Like
Y8 Games