When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles [1.x] [2.0]
ASPFAQs.com
Message Board
Related Web Technologies
User Tips!
Coding Tips
Search

Sections:
Book Reviews
Sample Chapters
Commonly Asked Message Board Questions
Headlines from ASPWire.com
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
Web Hosts
XML Info
Information:
Advertise
Feedback
Author an Article
Technology Jobs

















internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers
ASP ASP.NET ASP FAQs Message Board Feedback ASP Jobs
Print this page.

Windows Systems Administrator
Jupitermedia
US-CT-Darien

Justtechjobs.com Post A Job | Post A Resume

User Tips: Reading Flash File Information (.swf) through an ASP Page


This tip comes from Claudio Heidel

With the number of Web sites using Macromedia Flash Files (.swf files) to present content, as a Web developer it may come in handy to have an ASP page that could easily read various tidbits of information about a Flash file. Fortunately, Flash files save a plethora of useful information in their headers. This information can be read using the FileSystemObject through an ASP page! (To learn more about Flash, check out FlashKit.com!)

In order to ease the process of reading this information, I created a handy class to do the grunt work for me. (For more information on using classes with VBScript, be sure to read: Using Classes within VBScript.) The class I created returns the following information about a Flash file:

SWFDump Class
PropertyDescription
VersionThe version of the Flash file (3,4 or 5 at the moment)
HeightExpresed in pixels.
WidthExpresed in pixels.
xMinExpresed in Twips (20 twips = 1 pixel)
xMaxExpresed in Twips
yMinExpresed in Twips
yMaxExpresed in Twips
FileSizeThe total size of the .swf file.
FrameRateHow many frames are in the Flash file.
FrameCounterFrame counter information.

The use of the SWFDump class is very simple. First off, I recommend that you place it in an include file so that you can easily include the class in the files that need to read Flash file information. (For more information on server-side includes be sure to read: The Low-Down on #include.) I chose to name my include file swfheaderdump.inc. To use the class, simply use code like the following:

<!-- #include file="swfheaderdump.inc" -->
<%
'-------------------------------------------------------------
'  Create Date : 17/10/2001 (dd/mm/yyyy)
'  Mod. Date   : 17/10/2001
'  Author      : Claudio Heidel (heidel@f256.com)
'-------------------------------------------------------------
    
' Pass the SWF name in querystring this way
' swfdump.asp?swf=yourmovie.swf
    
  set myObj = new swfdump
  myObj.SWFDump (Server.MapPath(request("swf")))
    
  Response.Write "Heigt (pixel)     = " & myObj.Heigt      & "<br>"
  Response.Write "Width (pixel)     = " & myObj.Width      & "<br>"
  Response.Write "Version           = " & myObj.Version    & "<br>"
  Response.Write "FileLen (bytes)   = " & myObj.FileLen    & "<br>"
  Response.Write "xMin (twips)      = " & myObj.xMin       & "<br>"
  Response.Write "xMax (twips)      = " & myObj.xMax       & "<br>"
  Response.Write "yMin (twips)      = " & myObj.yMin       & "<br>"
  Response.Write "yMax (twips)      = " & myObj.yMax       & "<br>"
  Response.Write "FrameRate         = " & myObj.FrameRate  & "<br>"
  Response.Write "FrameCount        = " & myObj.FrameCount & "<br>"
%>

Simple enough. The file swfheaderdump.inc needs to contain the full definition of the SWFDump class:

<%
'-------------------------------------------------------------
'  Create Date : 17/10/2001 (dd/mm/yyyy)
'  Mod. Date   : 17/10/2001
'  Author      : Claudio Heidel (heidel@f256.com)
'-------------------------------------------------------------

Class SWFDump

  Private header
  Private RECTdata
  Private nBits
  Private mversion
  Private mfilelen
  Private mxMin
  Private mxMax
  Private myMin
  Private myMax
  Private mheigt
  Private mwidth
  Private mframerate
  Private mframecount

  Private Sub Class_Initialize()

  End Sub

  Private Sub Class_Terminate()

  End Sub


  Private Function ReadHeader (filename)
     Const ForReading = 1, ForWriting = 2, ForAppending = 8
     Dim fso, f
     Set fso = CreateObject("Scripting.FileSystemObject")
     Set f = fso.OpenTextFile(filename, ForReading)
     ReadHeader = f.Read(21)
  End Function

  Private Function ToBin(inNumber, OutLenStr )
    Dim binary
    binary = ""
    do while inNumber >= 1
      binary = binary & inNumber mod 2
      inNumber = inNumber \ 2
    loop
    binary = binary & String(OutLenStr - len(binary), "0")
    ToBin = StrReverse(binary)
  End Function

  Private Function Bin2Decimal(inBin)
    Dim counter
    Dim temp
    Dim Value
    inBin = StrReverse(inBin)
    temp = 0
    For counter = 1 to Len(inBin)
      If counter = 1 then
        Value = 1
      Else
        Value = Value  * 2
      End If
      temp = temp + mid(inBin, counter ,1)  *  Value
    Next
    Bin2Decimal = temp
  End Function

  Public Function SWFDump(fileName)

    header = ReadHeader (fileName)
    mversion = asc(mid(header,4,1))
    mfilelen = asc(mid(header,5,1))
    mfilelen = mfilelen + asc(mid(header,6,1)) * 256
    mfilelen = mfilelen + asc(mid(header,7,1)) * 256 * 256
    mfilelen = mfilelen + asc(mid(header,8,1)) * 256 * 256 * 256

    RECTdata = ToBin(asc(mid(header,9,1)),8)
    RECTdata = RECTdata & ToBin(asc(mid(header,10,1)),8)
    RECTdata = RECTdata & ToBin(asc(mid(header,11,1)),8)
    RECTdata = RECTdata & ToBin(asc(mid(header,12,1)),8)
    RECTdata = RECTdata & ToBin(asc(mid(header,13,1)),8)
    RECTdata = RECTdata & ToBin(asc(mid(header,14,1)),8)
    RECTdata = RECTdata & ToBin(asc(mid(header,15,1)),8)
    RECTdata = RECTdata & ToBin(asc(mid(header,16,1)),8)
    RECTdata = RECTdata & ToBin(asc(mid(header,17,1)),8)

    nBits = Mid(RECTdata,1,5)
    nBits = Bin2Decimal(nBits)

    mxMin =  Bin2Decimal(Mid(RECTdata,6,nBits))
    mxMax =  Bin2Decimal(Mid(RECTdata,6 + nBits * 1 ,nBits))
    myMin =  Bin2Decimal(Mid(RECTdata,6 + nBits * 2 ,nBits))
    myMax =  Bin2Decimal(Mid(RECTdata,6 + nBits * 3 ,nBits))

    mheigt = (myMax - myMin) / 20
    mwidth = (mxMax - mxMin) / 20

    mframerate = asc(mid(header,18,1))

    mframecount = asc(mid(header,19,1))
    mframecount = mframecount + asc(mid(header,20,1)) * 256

  End Function


  Public Property Get Heigt()
    Heigt = mheigt
  End Property

  Public Property Get Width()
    Width = mwidth
  End Property

  Public Property Get Version()
    Version = mversion
  End Property

  Public Property Get FileLen()
    FileLen = mfilelen
  End Property

  Public Property Get xMin()
    xMin = mxMin
  End Property

  Public Property Get xMax()
    xMax = mxMax
  End Property

  Public Property Get yMin()
    yMin = myMin
  End Property

  Public Property Get yMax()
    yMax = myMax
  End Property

  Public Property Get Framerate()
    Framerate = mframerate
  End Property

  Public Property Get Framecount()
    Framecount = mframecount
  End Property
End Class
%>

I hope you find this contribution useful and handy! If anybody has any questions please email me at heidel@f256.com or visit http://www.f256.com

Happy Programming!

Return to user tips...


Windows Internet Technology | ASP.NET [1.x] [2.0] | ASPMessageboard.com | ASPFAQs.com | Advertise | Feedback | Author an Article



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Win Server ‘08
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES