[AIR] Read and write data

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.