Reading parameters of a Macromedia Flash (SWF) file using ASP

Ever wanted to read the properties of a SWF file such as height and width? Well, I did. Openswf.org was a good starting point for me. They have a SWF parser written in C++ that can grab all the information you need. There are also a number of server-side objects that can do the trick as well. However, I needed a solution that would work without any custom server-side objects. So, I went on my merry way to try and convert the C++ code into JavaScript or VBScript. In the end, I created something that was a combination of both.

If you check out the code, you'll notice that it's broken down into essentially three parts. The first part is some JavaScript functions, the second is some VBScript functions and then I have the actual VBScript code that calls all my functions.

The way I use this is as follows:

dim astfilename
astfilename = "c:\myflashfile.swf"
<!--#include file="swfparser.asp" -->

After I've done this, I will have access to the following variables:

  • strFilepath : which should be the same as astfilename
  • isFlash : a boolean variable
  • intVersion : what version of Flash
  • swfwidth : the width of the Flash
  • swfheight : the height of the Flash

This code can also be expanded to grab some addiitional information such as frame rate.

Download the code

Update:
Some time after I created this article I came across another site who created a VBScript class to accomplish the same task. Check out this user tip on 4guysfromrolla.com.

Published October 31, 2001 · Updated September 17, 2005
Categorized as ASP
Short URL: https://snook.ca/s/105

Conversation

6 Comments · RSS feed
Jonathan Snook said on November 20, 2003

Just a quick note that this only works on Flash files up to version 5. In Flash 6, they implemented compression using the zlib format. If somebody comes up with a vbscript or javascript approach to decompress it, it should be easy enough to grab these parameters then.

Bhavin patel said on October 18, 2005

hi all...

can u plz send a clear idea about how to find out the heigh and width parameters of uploaded files...

Thanks...

Mark said on October 07, 2006

one line of code includes

if ucase(strTag) = "FWS" then isFlash=true

Well, a compressed flash file is "CWS", and you need gzip compression to uncompress everything from the 8th byte and on. Can you help us out with that?

Jonathan Snook said on October 08, 2006

I never got around to developing an ASP gzip decompressor. Creating one isn't something I'm interested in as ASP is certainly not as popular as it once was. Good luck with your project.

Prakash said on November 01, 2006

Hi,
I have checked the swf information reading code...Its not working for flash version 7...

PLease advice me.

Thanx & Rgds,
Prakash

Bruce said on September 01, 2007

I will use this code for flash games page on my sport web page.

Thank you very much.

Sorry, comments are closed for this post. If you have any further questions or comments, feel free to send them to me directly.