5 Replies - 1092 Views - Last Post: 24 September 2009 - 05:39 AM

#1 ktrrzn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-September 09

To read any file with flash and change that files to binary format

Posted 11 September 2009 - 08:11 AM

I want to know about how to read files from the flash and
how to change this files to binary format files.
I also want to know about delay function.
Is This A Good Question/Topic? 0
  • +

Replies To: To read any file with flash and change that files to binary format

#2 calebjonasson  Icon User is offline

  • $bert = new DragonUnicorn(); $bert->rawr();
  • member icon

Reputation: 209
  • View blog
  • Posts: 989
  • Joined: 28-February 09

Re: To read any file with flash and change that files to binary format

Posted 13 September 2009 - 05:04 PM

First things first you are going to have to take a leap and try to suply us with some code. Also when asking how to read a file into binary it helps if you tell us what kind of file you would like to turn into binary.
Was This Post Helpful? 0
  • +
  • -

#3 ktrrzn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-September 09

Re: To read any file with flash and change that files to binary format

Posted 22 September 2009 - 05:10 AM

For first,i want to read the text file from local harddrives or from network.
i want to change this text file to binary format.So, i can chop it into packages.
i'm trying to simulate communication system.So, i need to demonstrate the process between two transmission system.
I searched about delay function in Flash 2008. It doesn't describe about delay function.It only describe about
setInterval() and clearInterval
.It only repeated with milliseconds.I want to show animation with dealy without using frame.only with action script.
Thanks for replying.
Was This Post Helpful? 0
  • +
  • -

#4 ktrrzn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-September 09

Re: To read any file with flash and change that files to binary format

Posted 23 September 2009 - 05:46 AM

function convertToBinary(numberToConvert:Number):String { 
 var result:String = ""; 
 for (var i = 0; i<16; i++) { 
 // Extract least significant bit using bitwise AND 
 var lsb:Number = numberToConvert & 1; 
 // Add this bit to the result 
  result = (lsb ? "1" : "0")+result; 
 // Shift numberToConvert right by one bit, to see next bit 
 numberToConvert >>= 1; 
 } 
 return result; 
} 

var a:String="Hello";
var b:Array=new Array();
for(var i:Number=0;i<a.length;i++){
	var tmp:Number=a.charCodeAt(i);
	trace(a.charCodeAt(i));
	trace(convertToBinary(tmp)); 
	b.push(tmp);
}


This is my code to convert to binary format.
but i can't read the file .
so i need the function to read the files
i really need.
Thanks for your helps.
Was This Post Helpful? 0
  • +
  • -

#5 ktrrzn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-September 09

Re: To read any file with flash and change that files to binary format

Posted 24 September 2009 - 05:33 AM

View Postktrrzn, on 23 Sep, 2009 - 04:46 AM, said:

function convertToBinary(numberToConvert:Number):String { 
 var result:String = ""; 
 for (var i = 0; i<16; i++) { 
 // Extract least significant bit using bitwise AND 
 var lsb:Number = numberToConvert & 1; 
 // Add this bit to the result 
  result = (lsb ? "1" : "0")+result; 
 // Shift numberToConvert right by one bit, to see next bit 
 numberToConvert >>= 1; 
 } 
 return result; 
} 

var a:String="Hello";
var b:Array=new Array();
for(var i:Number=0;i<a.length;i++){
	var tmp:Number=a.charCodeAt(i);
	trace(a.charCodeAt(i));
	trace(convertToBinary(tmp)); 
	b.push(tmp);
}


This is my code to convert to binary format.
but i can't read the file .
so i need the function to read the files
i really need.
Thanks for your helps.

Was This Post Helpful? 0
  • +
  • -

#6 ktrrzn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-September 09

Re: To read any file with flash and change that files to binary format

Posted 24 September 2009 - 05:39 AM

View Postktrrzn, on 23 Sep, 2009 - 04:46 AM, said:

this.createEmptyMovieClip("line_mc", this.getNextHighestDepth);
line_mc.lineStyle(1, 0x0000FF, 100);
line_mc.moveTo(1, 50);
//////////////////////////////////////////////////////////////////
//var last_y:Number=10;
_global.maxLength = 8;
var interval:Number = 2;
var amplitude:Number = 10;
var lastBi:Number = 1;
var linex:Number = 1;
var liney:Number = 50;
var rotate:Number = 1;
var elevation:Number = 75;
var azimuth:Number = 150;
////////////////////////////////////////////////////////////////
function drawWave(newBi:Number) {
	if (newBi != lastBi) {
		var tmp:Number = newBi;
		if (newBi == 0) {
			tmp = -1;
		}
		//to inverse the y axis direction 
		line_mc.lineTo(linex, liney+(amplitude*tmp));
		//to save the y value
		liney += (amplitude*tmp);
		//must move to same interval
		line_mc.lineTo(linex+interval, liney);
	}
	line_mc.lineTo(linex+interval, liney);
	linex += interval;
	lastBi = newBi;
}
/////////////////////////////////////////////////////////////////
draw_btn.onPress = function() {	
	var loadit_lv:LoadVars = new LoadVars();
	loadit_lv.load("D:\\study\\virus.txt");
	loadit_lv.onData = function(src:String) {
		if (src != undefined) {
			var cc_ar:Array;
			var jj:String;
			trace("ok");
			cc_ar = accept(src);
			jj = reverse(cc_ar);
			(jj == src ? trace("right") : trace("wrong"));
			for (var i:Number = 0; i<cc_ar.length; i++) {
				for (var j:Number = 0; j<maxLength; j++) {
					//substr choose the string from start and length
					drawWave(Number(cc_ar[i].substr(j, 1)));
				}
			}
		} else {
			trace("Could not load text file.");
		}
		
	};
};
//////////////////////////////////////////////////////////////
function convertToBinary(numberToConvert:Number):String {
	var result:String = "";
	for (var i = 0; i<maxLength; i++) {
		// Extract least significant bit using bitwise AND 
		var lsb:Number = numberToConvert & 1;
		// Add this bit to the result 
		result = (lsb ? "1" : "0")+result;
		// Shift numberToConvert right by one bit, to see next bit 
		numberToConvert >>= 1;
	}
	return result;
}
///////////////////////////////////////////////////////////////////////
function convertToCharacter(binaryToConvert:String):Number {
	var result:Number = 0;
	var num:Number = 0;
	for (var i = maxLength-1; i>=0; i--, num++) {
		result += Number(binaryToConvert.charAt(i))*Math.pow(2, num);
	}
	return result;
}
///////////////////////////////////////////////////////////////////////
function accept(s:String):Array {
	//for String to binary array
	var b:Array = new Array();
	for (var i:Number = 0; i<s.length; i++) {
		var tmp:String = convertToBinary(s.charCodeAt(i));
		b.push(tmp);
	}
	return b;
}
///////////////////////////////////////////////////////////////////////////
function reverse(a:Array):String {
	//for binary array to string file
	var tmp:String = chr(convertToCharacter(a[0]));
	for (var i:Number = 1; i<a.length; i++) {
		tmp += chr(convertToCharacter(a[i]));
	}
	return tmp;
}
//////////////////////////////////////////////////////////////////


This is my complete code to convert to binary format.
and change the binary array to string again.
I can read the text files now.
but i can create the text files by using above codes.
And i also want to read other files types (such as mp3,exe,jpg)
and require them to convert to binary format, chop them and combine them again to reformat as their original formats as respectively.
Another question is can i read the data from microphone as waveform.
I need to show that waveform and slice this waveform into binary format.
and again create the mp3 file from the binary format.
There are more questions I think,sorry for interrupt you all.
Thanks for your help, anyway for creating this community website.
I'm very appreciate to join this community and happy to share with you.

Thanks for your helps.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1