To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here


A Flash Developer Resource Site

Go Back   Flash Kit Community Forums > General Help > Scripting & Backend

Reply
 
Thread Tools Display Modes
Old 04-15-2002, 10:16 AM   #1
cassell
Junior Member
 
Join Date: Apr 2002
Posts: 4
I'm trying to find the stage height and width of .swf's and pass it to a movie with xml.

I found these two relevant posts on how to grab the height and width of a gif and the theory behind doing it for a swf:
http://board.flashkit.com/board/show...hreadid=285002
http://board.flashkit.com/board/show...hreadid=122862

I'm a perl novice. Can someone post an example script that would parse the correct header? Also, in the second example, it states that the xmax and ymax would be returned. But that's not the stage size. Is there a way to get the stage size?
cassell is offline   Reply With Quote
Old 04-15-2002, 03:43 PM   #2
Musicman
Moderator
 
Join Date: Feb 2001
Posts: 12,931
Hi,

since this is probably not exactly novice's reading: you will find the theory behind the code at http://www.openswf.org - check the spec section
Code:
$buffer = 0;
$bufbits = 0;
sub readnbits
{       my $n = shift;
        my $ret = $buffer;
        if($n == $bufbits)
        {       $bufbits = 0;
                $buffer = 0;
                return $ret;
        }
        if($n > $bufbits)
        {       $n -= $bufbits;
                while($n > 8)
                {       $ret <<= 8;
                        read SWF, $buffer, 1; $buffer = ord($buffer);
                        $ret += $buffer;
                        $n -= 8;
                }
                read SWF, $buffer, 1; $buffer = ord($buffer);
                if($n > 0)
                {       $ret <<= $n;
                        $bufbits = 8 - $n;
                        $ret += $buffer >> (8-$n);
                        $buffer &= (1 << $bufbits)-1;
                }
                return $ret;
        }
        $ret = $buffer >> ($bufbits-$n);
        $bufbits -= $n;
        $buffer &= (1 << $bufbits)-1;
        return $ret;
}
sub readnSbits
{       my $n = shift;
        my $temp = readnbits($n);
        return ($temp - (1 << $n)) if($temp & (1 << ($n-1)));
        return $temp;
}

sub swfhdr
{       my $swf = shift;
        my $buf, $vers, $fsize, $nbits, $xl, $yl, $xr, $yr, $rect, $rate, $frames;
        open SWF, $swf || return undef;
        read SWF, $buf, 3;
        return undef if($buf ne "FWS");
        read SWF, $vers, 1; $vers = ord($vers);
        read SWF, $buf, 4; ($fsize) = unpack "V", $buf;
        $nbits = readnbits(5);
        $xl = readnbits($nbits); $xr = readnbits($nbits);
        $yl = readnbits($nbits); $yr = readnbits($nbits);
        my $tmplen = (tell SWF) - 8;
        seek SWF, 8, 0;
        read SWF, $rect, $tmplen;
        read SWF, $buf, 4;
        ($rate, $frames) = unpack("vv", $buf);
        return ($vers, $fsize, $xr-$xl, $yr-$yl, $rect, $rate, $frames);
}

sub writeswfheader
{       my ($swf, $vers, $fsize, $rect, $rate, $frames) = @_;
        open OSWF, ">$swf" || die "cannot write to $swf\n";
        print OSWF "FWS" . chr($vers);
        print OSWF pack("V", $fsize) . $rect . pack("vv", $rate, $frames);
}
## testing
($vers, $fsize, $x, $y, $rect, $rate, $frames) = swfhdr ("3554.swf");
printf "movie size %f %f\n", $x/20, $y/20;
printf "rate %f frames %d\n", $rate/256, $frames;

writeswfheader("test3554.swf", $vers, $fsize, $rect, $rate, $frames);
Have fun

Musicman
Musicman is offline   Reply With Quote
Old 04-16-2002, 09:06 AM   #3
cassell
Junior Member
 
Join Date: Apr 2002
Posts: 4
Cool. Thanks a lot. Worked like a charm.
cassell is offline   Reply With Quote
Reply

Go Back   Flash Kit Community Forums > General Help > Scripting & Backend

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:07 AM.


internet.commerce
Be a Commerce Partner
 »  »  »  »  »  »  »
 »  »  »  »  »  »
 

    

Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.