Create a new two Flash air document READ.FLA,WRITE.FLA;WRITE.FLA as the write data, read.fla as the reading data, only as an example of testing.
Write the code at the first frame of the Write.fla keyframe:
ImportFlash.utils.ByteArray;ImportFlash.filesystem.File;ImportFlash.filesystem.filestream;const Text:int= 2;varValuestr:string ="Hello!"varBytes:bytearray =NewByteArray (); Bytes.writeint (TEXT); Bytes.writeint (16 +valuestr.length); Bytes.writeint (100); Bytes.writeint (150); bytes.writeutfbytes (VALUESTR);varFile:file = File.desktopDirectory.resolvePath ("TEST.ABC");varFs:filestream =NewFileStream (); Fs.open (file, Flash.filesystem.FileMode.WRITE); fs.writebytes (bytes,0, bytes.length); Fs.close ();
After publishing the Test.abc file will be generated on the desktop, ABC is the extension, can be arbitrarily named;
Write the code at the first frame of the Read.fla keyframe:
ImportFlash.utils.ByteArray;ImportFlash.filesystem.File;ImportFlash.filesystem.FileStream;ImportFlash.text.textfield;const Text:int= 2;varBytes:bytearray =NewByteArray ();varFile:file = File.desktopDirectory.resolvePath ("TEST.ABC");varFs:filestream =NewFileStream (); Fs.open (file, Flash.filesystem.FileMode.READ); fs.readbytes (bytes); Fs.close ();if(Bytes.readint () = =TEXT) { varLength:int =Bytes.readint (); varTx:int =Bytes.readint (); varTy:int =Bytes.readint (); varstr:string = Bytes.readutfbytes (length-16); varT:textfield =NewTextField (); T.x=TX; T.y=Ty; T.text=str; AddChild (t);}
After publishing, we will find that the data written by Write.fla is read in Read.fla;
File read and write data is read and write in sequence, first read first, then read after writing;
[AIR] Read and write data