5.
Make a single exe file
Some larger projects need to incorporate many
resource files other than the main movie.
E.g.. The required resource files on disk
The main movie needs to load these resource
files while playing.
First, create the main movie using Macromedia
Flash MX. Providing the resource files are put
in "c:\flash\single", we save the
main movie in the folder, and name it "single.swf".
In "single.swf", we load the resources
with relative path names. For example, to load
the movie "Shanghai.swf", we call
the method "loadMovie" in Action Script
like this
//The "shanghai.swf" is in "c:\flash\single\resource\movies\tour"
folder
loadMovie("resource/movies/tour/shanghai.swf",
shanghai); |
Now we can create a new project by adding
the main movie into the movie list in SWFKit.
Where should we put the resource files? Just
put them in the same folder of the output executable
file?
Yes, if the "pack movies" option in SWFKit
is not checked, it can work if you put the resources
in the same folder of the output executable
file.
When the "pack movies" is not checked, SWFKit
will not pack the main movie into the output
exe file, but copy it into the same folder of
the exe file. That is to say, the main movie
and the resources will be in same folder, just
like the Flash authoring environment.
But if the "pack movies" is checked, things
are changed. SWFKit will pack the main movie
into the output exe file. When the exe file
is about to run, the packed movie will be extracted
into a temporary folder, then the movie and
the resources are in different folder. When
the movie calls the method
| loadMovie("resource/movies/tour/shanghai.swf",
shanghai); |
The Flash Player cannot find the "Shanghai.swf",
for the movie is in the temporary folder and
"resource/movies/tour/shanghai.swf"
is not in this folder.
Even though you can make it to work by not
checking the "pack movies" option,
it isn't what we want. We want to make a single
exe file, but in this way we will get an exe
file with many external resource files.
The following section introduces you a way
to make a single executable file. It will always
work even if you don't want to make a single
exe file (unchecking the "pack movies"
or the "pack attachments" options).
To resolve the problem in the above section,
we can add the resources into the attachment
list. In SWFKit, create subfolders such as "Movies",
"Sounds" and "Pictures"
under the "Application" folder and
add the resource files into the corresponding
folders. Then in the attachment list, we have
the same directory structure as on the disk.
Check the "pack movies" and "pack
attached file" options. SWFKit will pack
all the files into the output executable file,
that is to say, we can get a single exe file.
Is this enough? No, the application will extract
the packed movies automatically when it is about
to run, but won't extract the attached files.
The resource file must be extracted before they
can be loaded by the main movie. You must tell
SWFKit to do so in FFish Script (in the "initialize"
script)
| var res_path = getAdditionalFile();
Application.setBasePath(res_path); |
If you call the "getAdditionFile"
method later with the same parameter, SWFKit
will check to see if the required files or folders
have been extracted. If the files or folders
have already been extracted, it won't do extraction
again.
The folder SWFKit extracts the attached files
into is different from the temporary folder
for extracting the packed movies. The application
cannot work if you don't set the base directory
to it. So we must set the base directory of
the application to the folder contains the extracted
resource files using the "Application.setBasePath"
method.
To make a single exe file, you should
- Add the additional files into the attachment
list and make the directory structure
same as on disk.
- In the "Initialize" script, tell
the application to extract the attachments
by calling the "getAdditionFile" method.
- Set the base directory to the folder contains
the extracted additional files (the "getAdditionalFile"
method returns the path name of the folder).
Whether the "pack movies" and "pack
attached file" options are set or not,
the applications built in this way will always
work.
|