1 Replies - 3198 Views - Last Post: 23 April 2013 - 05:55 PM

#1 mudz27  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 20-April 13

How to use a .txt file instead of .dat file in Actioscript 3 flash cs6

Posted 20 April 2013 - 04:36 PM

Hi i want my speedometer app which im making in flash pro cs6 using air for android to read the speed from .txt file instead of a .dat file.

How do i go about changing this code below done in Actionscript 3 as i want to be able to change the numbers and test the speedometer App works again with different speed info.

Also could you let me know how would i put the numbers in the .txt file to be read.

At the moment i am just using the gps.dat binary logged speed file from my phone to test this but i cannot change the values of this .dat file so i can't test some top speeds.

So what i want is my code to read a .txt file instead of a binary .dat file which i cant edit as it's just gps data unreadable in a text editor that are stored on my phone whilst i was driving, which i have copied and have been using to simulate my speedometer app whilst testing on my computer in flash pro is it possible to modify my code to use a .txt instead of there other .dat file i been using do this at all.

i look forward to any responses Thank - You

Here is the code i have how would i rectify to use a txt file:

    package
    {
	import flash.events.EventDispatcher;
	import flash.events.GeolocationEvent;
	import flash.events.TimerEvent;
	import flash.filesystem.File;
	import flash.filesystem.FileMode;
	import flash.filesystem.FileStream;
	import flash.utils.Timer;

	public class GeolocationSimulate
		extends EventDispatcher
		implements IGeolocation
	{	
		static private const DEFAULT_DELAY :Number = 1000;
		static private const FILE          :String = "gps.dat";
		
		private var filestream :FileStream;
		private var timer      :Timer;
		
		public function GeolocationSimulate()
		{
			timer = new Timer( DEFAULT_DELAY );
			timer.addEventListener( TimerEvent.TIMER, handleTimer );
			timer.start();
			
			var file :File = File.userDirectory;
			file = file.resolvePath( FILE );			
			filestream = new FileStream();
			filestream.open( file, FileMode.READ );
		}
		
		public function setRequestedUpdateInterval( interval :Number ) :void
		{
			timer.delay = interval;
		}
		
		private function handleTimer( e :TimerEvent ) :void
		{
			if( filestream != null )
			{
				var speed :Number;

				if( filestream.bytesAvailable )
				{
					speed = filestream.readFloat();
				}
				else
				{
					filestream.position = 0;
					speed = filestream.readFloat();
				}
			
				dispatchEvent(
					new GeolocationEvent(
						GeolocationEvent.UPDATE,
						false,
						false,
						0,
						0,
						0,
						0,
						0,
						speed,
						0,
						0
					)
				);
			}
		}
	}
}


 


Is This A Good Question/Topic? 0
  • +

Replies To: How to use a .txt file instead of .dat file in Actioscript 3 flash cs6

#2 mudz27  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 20-April 13

Re: How to use a .txt file instead of .dat file in Actioscript 3 flash cs6

Posted 23 April 2013 - 05:55 PM

anyone??? please help im really stuck on this
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1