13 January 2006

Coding:Creating Trials for Flash Lite Apps

This is Richard Legger answer for David Williams question on the Flash Lite Yahoo Group asks, how do I make time limited trials in Flash Lite 1.1?

There are a few options to consider:

  • Time out after a few minutes each time.
  • Time out after X days and never run again.
  • Lose functionality after X days or weeks.

Unfortunately it is getting late and I have work to do, so I've only got time to cover the first in that list, but I'm still writing my book on Flash Lite which is due March, and that will have detailed instructions and samples for each - end plug.

So the code for the first example is very simple, and I've included an FLA which contains a movie clip in the library that you can simply drag into your game or app to make sure it exits 3 minutes after starting up.

First up, create a new Flash document using a mobile template, and create a new movie clip, called "TrialMaker". Edit that movie clip and type the following code on frame 1:

timeout = 180;
startTime = getTimer();

Next up, create a keyframe on frame 10, and add the following:

if(getTimer()-startTime > timeout*1000)
{
fscommand("quit");
}

gotoAndPlay(2);

I chose frame 10, as this creates an automatic loop, a loop that doesn't execute code all that often thus having a negligable impact on your game execution speed whilst remaining fairly accurate (which we all know is essential for Flash Lite games). You can modify the value of timeout to any number of seconds you wish, I chose 3 minutes at Davids request.

Download FLA.

If you are lucky enough to be using Flash Lite 2, you can simply add the following code to frame 1:

setInterval(function() { fscommand("quit"); }, 180000);

PPL IAIN Syekh Nurjati Cirebon

Jika ditanya apa yang kau suka dari kehadiran mereka? Mereka punya jawabannya : semangat yang tinggi dengan keingintahuan yang tipikal mahas...