Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package  {
  2.    
  3.     import flash.events.GeolocationEvent;
  4.     import flash.sensors.Geolocation;
  5.     import flash.display.MovieClip;
  6.     import flash.text.TextField;
  7.     import flash.events.TimerEvent;
  8.     import flash.display.*;
  9.    
  10.     public class MainClass extends MovieClip {
  11.  
  12. //////////////////////////////////////////////////////////////////////////////////
  13. //////////////////////////////////////////////////////////////////////////////////
  14.            
  15.         // textfields
  16.         private var lat_txt:TextField = new TextField();
  17.         private var long_txt:TextField = new TextField();
  18.         private var accuracy_txt:TextField = new TextField();
  19.         private var feedback_txt:TextField = new TextField();
  20.         private var badgePosNumber:Array = new Array;
  21.        
  22.         // custom classes
  23.         private var starBadges:Badges;
  24.         private var sInactive:starInactive;
  25.         private var sActive:starActive;
  26.        
  27.         // position data
  28.         public var totalDistance:Number = new Number(1000); // user defines later.
  29.         public var lapStop:Number = new Number(5); // user defines later.
  30.         public var badgeCount:Number;
  31.         public var movedDistance:Number = new Number(500);  // user defines later.
  32.         public var pLeft:Number = 60;
  33.        
  34.         // arrays
  35.         public var inActiveLocation:Array = new Array; // .x location for inactive badge
  36.         public var inactiveA:Array = new Array; // inactive badges to array
  37.         //
  38.         public var activeLocationA:Array = new Array; // .x location for active badge
  39.         public var activeA:Array = new Array; // active badges to array
  40.        
  41. //////////////////////////////////////////////////////////////////////////////////     
  42. //////////////////////////////////////////////////////////////////////////////////
  43.        
  44.         public function MainClass()
  45.         {              
  46.             stage.scaleMode = StageScaleMode.NO_SCALE;
  47.             stage.align = StageAlign.TOP;
  48.             getLapStops();
  49.             initGPS();     
  50.         }
  51.         public function getLapStops():void
  52.         {          
  53.             var badgeCount = new Number;           
  54.             for (var i = 0; i < lapStop; i++)
  55.             {
  56.                 badgeCount = (totalDistance / lapStop);
  57.                 badgeCount += i * (badgeCount);
  58.                 badgePosNumber.push(badgeCount);
  59.             }          
  60.            
  61.             badgePosNumber.toString([1]);
  62.             checkActiveStars();
  63.             //initGPS();
  64.         }
  65.         public function initGPS():void
  66.         {
  67.             if (!Geolocation.isSupported)
  68.             {
  69.                 var geo:Geolocation = new Geolocation();
  70.                 geo = new Geolocation();
  71.                 geo.setRequestedUpdateInterval(50);
  72.                 geo.addEventListener(GeolocationEvent.UPDATE,geolocationUpdateHandler);            
  73.                
  74.                 for (var i = 0; i < 5; i++)
  75.                 {              
  76.                     sInactive = new starInactive();                                            
  77.                     stage.addChild(sInactive);
  78.                     sInactive.y = 315;
  79.                     sInactive.x = pLeft + i * (20 + sInactive.width);
  80.                     inActiveLocation.push(sInactive.x);
  81.                     trace('Inactive star added at ||' +  sInactive.x);
  82.                     trace('inActiveLocation values ' + inActiveLocation);
  83.                     inactiveA.push(sInactive[0]);                                      
  84.                     trace(inActiveLocation[2]);
  85.                 }              
  86.             }          
  87.             else
  88.             {
  89.                 feedback_txt.text = "Seems like Geolocation isnt supported.";
  90.                 trace(feedback_txt.text);              
  91.             }
  92.             checkActiveStars();
  93.         }
  94.         public function geolocationUpdateHandler(event:GeolocationEvent):void
  95.         {
  96.             lat_txt.text = "Latitude: " + event.latitude;
  97.             long_txt.text = "Longtitude: " + event.longitude;
  98.             accuracy_txt.text = "Horizontal Accuracy: " + event.horizontalAccuracy;
  99.             addChild(lat_txt);         
  100.         }
  101.         public function checkActiveStars():void
  102.         {
  103.             sActive = new starActive;
  104.             if(badgePosNumber[0] <= movedDistance)
  105.             {
  106.                 trace("moved distance is greater than badgePosNumber " + badgePosNumber[0]);               
  107.                 addChild(sActive.push;
  108.                 sActive.y = 315;
  109.             }
  110.                        
  111.         }
  112.     }  
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement