What is binary data?
Binary data is just data embedded in your application. When you use a Play Sound action or Play Music, unless you specify play from file and use and expression, the music/sound gets embedded in your MFA, and then your application when you build it. Flash connverts sounds to MP3, of course, and Java only supports Wav right now. But Vitalize, Screensavers, and EXEs all support binary data.
However, only screensavers and EXEs can extract your custom-included binary data. This data can be included via the Binary Tab of the Data Elements window. You can access it by clicking the button next to the event editor button. It looks like a musical note with a paper.
What does the Binary Data tab look like?
Well, it looks something or other like this:
Here you can add and remove files from the list of files to include in the built application. These files are not saved with the MFA, and have to be accessed in a special way using some of MMF2's built in features. (Namely the Special Object)
When you want to use a file from here, you need to use the exact same path as is seen in this tab for it to work.
How do I use the files I have listed in the tab in my application?
Note that because the binary data files are only embedded in your built application, in some cases you might not be able to test this by simply running your application from MMF2. You have to build your application and run the file for it to work. However sometimes you can test it from MMF2. It just depends.
Once you have your binary data in the list, you can start to program your application for the files. Here is the process:
* Take note of the path of the file you want that is listed in the Data Elements' Binary Data tab. You will need to use this exact text every time you refer to the file. (I will refer to it as "{MyFile}")
(note: this path is saved in the EXE/SCR no matter what the compression. To save space and privacy, I recommend you use Windows Explorer's Map Network Drive feature. Open My Computer, go to Tools -> Map Network Drive. Select the drive letter that you want, then map it to the folder that has the file you want. Then instead of using the whole path, now you can just use, for example, Y:\File.wav)
* When you want to use the file, use the action Extract Binary File "{MyFile}" from the special object.
* When you want to reference the file for an extension or object or MMF2, or whatever, then use the expression BinFileTempName$("{MyFile}") from the special object to get the path for it.
* When you are done using the file, or your application is closing, then you should always release the file with the action Release Binary File "{MyFile}" from the special object.
And that's how you use it! This is also how the auto installer was made for Knytt Stories. The game files had to come out of somewhere!
Nice article! I haven't used binary files yet but I know generally how they work. Just wondering, is it "safe" to extract the binary file data into AppPath$, considering that some people might download it and run the exe from inside the zip (temp folder)?
You can't choose where to extract it to. It goes to some temporary directory, that is why there is an expression to get the path of it. Comment edited by LB on 6/4/2010
Oh and also, it is impossible to run a program from inside a zip folder. When you double click a file (like an EXE) in a zip folder, windows first extracts that file to a temp directory, and then runs it from there. So AppPath$ would return the temp directory where the program was extracted to. So I guess you could call it 'safe' if you wanted to. Comment edited by LB on 6/6/2010