SWF as embedded resource and .NET

  • Thread starter Thread starter photochop
  • Start date Start date
P

photochop

I know the question of whether or not a SWF file can be read in by a
..NET application has been asked a billion times, however, what I'm
asking is whether or not it is possible (any examples? tutorials? Flash
Object COM readme?) to embed a SWF file into your VS.NET project as a
resource, and then read in the file into the Flash object much the same
way that you currently do using the LoadMovie function that takes in a
layer and a file location path.

Anyone know of a way to load a SWF that is an embedded resource and not
in the physical directory path into a .NET application?

Thanks all
-Steve
 
Hi,

I know the question of whether or not a SWF file can be read in by a
.NET application has been asked a billion times, however, what I'm
asking is whether or not it is possible (any examples? tutorials? Flash
Object COM readme?) to embed a SWF file into your VS.NET project as a
resource, and then read in the file into the Flash object much the same
way that you currently do using the LoadMovie function that takes in a
layer and a file location path.

Anyone know of a way to load a SWF that is an embedded resource and not
in the physical directory path into a .NET application?

AFAIK you can insert any file as a resource, you later would have to
"de-embed" it in a temp file and feed this file to the flash player.

With the code below you check the resources for the expected name, save it
to a temp file and return the pathof the new file
Note that the original extension is also kept



static string ExtractResource( string resourceName)
{
//look for the resource name
foreach( string currentResource in
System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames()
)
if ( currentResource.LastIndexOf( resourceName) != -1 )
{
string fqnTempFile = System.IO.Path.GetTempFileName();
string path = System.IO.Path.GetDirectoryName( fqnTempFile);
string rootName= System.IO.Path.GetFileNameWithoutExtension(
fqnTempFile);
string destFile = path + @"\" + rootName + "." +
System.IO.Path.GetExtension( currentResource);

System.IO.Stream fs =
System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(
currentResource);

byte[] buff = new byte[ fs.Length ];
fs.Read( buff, 0, (int)fs.Length);
fs.Close();

System.IO.FileStream destStream = new System.IO.FileStream ( destFile,
FileMode.Create);
destStream.Write( buff, 0, buff.Length);
destStream.Close();

return destFile;
}

throw new Exception("Resource not found : " + resourceName);

}
 
I just have to say thank you for your post and routine: ExtractResource. I have been trying to find something like this that would open an embedded Excel file that I am using basically as a report layout. I didn't want the user to have to have the Excel file on their machine (they'd just erase it or change something in it!) This worked like a charm.
 
Back
Top