Posted By

burnandbass on 01/02/12


Tagged

object Shared compare dates period trial


Versions (?)

Trial period


 / Published in: ActionScript 3
 

Use this if you need to make "trial period" to your app with Shared Objects. It is veri simple to use:

if(Validator.isActive(0,0,1)){ trace("ENTER"); } else { trace("YOUR DEMO IS OVER"); }

this demo will be active only 1 minute. Pass the validor Validator.isActive(days,hours,minutes) number of days, hours and minutes and it will return boolean.

  1. package {
  2.  
  3. import flash.events.EventDispatcher;
  4. import flash.net.SharedObject;
  5.  
  6. public class Validator extends EventDispatcher {
  7.  
  8. public static var _active:Boolean;
  9. public static var _data:SharedObject;
  10. public static var _currentDate:Date;
  11. public static var _expireDate:Date;
  12.  
  13. public function Validator() {
  14. // constructor code
  15. }
  16.  
  17. public static function isActive(days:Number=0, hours:Number = 0, minute:Number = 0):Boolean{
  18. _data = SharedObject.getLocal("exp_date");
  19. _currentDate = new Date();
  20.  
  21. if(_data.data.expireDate == undefined){
  22. _expireDate = new Date(_currentDate.fullYear, _currentDate.month, _currentDate.date + days, _currentDate.hours + hours, _currentDate.minutes + minute);
  23. _data.data.expireDate = _expireDate;
  24. _active = true;
  25. } else {
  26. _expireDate = _data.data.expireDate;
  27.  
  28. trace("Current date : " + _currentDate);
  29. trace("Expiring date: " + _expireDate);
  30.  
  31. if(_currentDate.getTime() <= _expireDate.getTime()){
  32. _active = true;
  33. } else {
  34. _active = false;
  35. }
  36. }
  37.  
  38. return _active;
  39. }
  40.  
  41. }//end
  42. }

Report this snippet  

You need to login to post a comment.