BinaryXtra for Macromedia DirectorBinaryXtra object model
BinaryXtra is organized similar to ADOxtra and VbScriptXtra. BinaryXtra implements several xtra-level methods and binary data wrapper. Xtra level methods provide basic xtra initialization, version information and binary wrapper creation.
Binary wrapper provides the main functionality of the xtra. At first, it holds the binary data. Also it provides methods and properties for accessing binary data.
Creating binary data wrapper and filling it with a data
There are several ways how binary wrapper instance can be created. It may be created either directly by Create xtra-level method or indirectly by other xtras (like ADOxtra or VbScriptXtra).
Following line creates a new empty binary wrapper:
binary=xtra("BinaryXtra").Create()
Use Size property to check the size of the wrapped data in bytes:
put binary.Size
It will return zero for new empty binary wrapper.
Sample below demonstrates indirect creation of the wrapper by VbScriptXtra:
rst.Open("SELECT BLOB_field FROM SomeTable")
binary=rst.fields["BLOB_fields"].value
Note: for this sample to work BinaryXtra has to be loaded (exists in Xtras folder).
This sample creates a new binary wrapper and fills it with the data contained in the database.
There are several other ways to put actual data into a binary wrapper. Use ReadFromFile method to put the contents of file into a wrapper:
binary.ReadFromFile("SomeFilePathName")
put binary.Size
Use Media property to put the media of any cast member into the wrapper:
binary.Media=member("SomeMember").media
put binary.Size
Use Picture property to put the picture data into the wrapper:
binary.Picture=member("SomeMember").picture
put binary.Size
Also binary wrapper can allocate a piece of memory, which could be filled by Lingo script directly byte by byte (array of bytes):
binary.Allocate(1000)
repeat with i=1 to binary.Size
binary.byte[i]=i
end repeat
put binary.Size
Using binary data wrapper
Once binary wrapper is created, it may be used to directly access the bytes of data. It may be used to apply binary data as a media or picture data. Also the binary contents of the wrapper can be written into a file or passed to other xtra.
Sample below demonstrates using binary wrapper to write the media of member into a BLOB field of a database:
binary=xtra("BinaryXtra").Create()
binary.Media=member("SomeMember").media
rst.Open("SELECT BLOB_field FROM SomeTable")
rst.fields["BLOB_fields"].value=binary
rst.Update()
Use WriteToFile method to create a file and write the binary data into it:
binary.WriteToFile("SomeFilePathName")
Use Byte[] indexed property to directly access bytes of the binary data:
repeat with i=1 to binary.Size
put binary.byte[i]
end repeat
Binary wrapper allows to convert binary contents into a string using String method:
put string(binary)
Note: this conversion treats the binary data as zero terminated string, so the whole binary contents will be output as string only when there are no zeros in binary data.
There is also a HexString method which allows to output binary data in a hexadecimal text form.
|