Is it possible to capture/find the dimensions of a flash movie as it loads into a webpage?
I have a cms where my client loads banner ads from their clients. They don't know the dimensions or don't want to enter them when they upload the banners. Is it possible to capture the dimensions to set the object attributes as we grab the movies from the db to display in the page? I read that the movie开发者_运维技巧 dimensions are available in the loaderinfo object, but this is a AS3 object right? Are AS3 objects available outside the flash movie? Can I access the loaderobject via javascript? The Flash movies we're trying to load are not ours, we don't have access to the flas or anything like that so we can't edit anything to do with the movies themselves.
This might help
http://blog.codefidelity.com/?p=14
I think you can even use jquery with more ease
Try something like $("object").height() and $("object").width(); if you have just one object tag for flash .
You can also do something server side, if you want the size to be stored 100% accurately without user input.
This python script, for example, will output the compression type, version, size (compressed or uncompressed) and the dimensions.
#!/usr/bin/env python
import bitstring
import zlib
swf_file = file("test.swf", "rb")
swf = swf_file.read()
swf_file.close()
bits = bitstring.ConstBitStream(filename="test.swf")
type = "".join(map(chr, bits.readlist('uint:8, uint:8, uint:8')))
print "Compression: ", type
print "Version: ", bits.read('uint:8')
swf_length = bits.read('uintle:32')
if type == 'CWS':
print "Compressed Size: ", swf_length
f = zlib.decompress(bits.bytes[8:], zlib.MAX_WBITS)
bits = bitstring.ConstBitStream(bytes=f, length=swf_length * 8 - 64)
else:
print "Uncompressed Size: ", swf_length
nbits = bits.read('uint:5')
xmin, xmax, ymin, ymax = bits.readlist('uint:{size}, uint:{size}, uint:{size}, uint:{size}'.format(size = nbits))
print "Dimensions: {x}x{y}".format(x = (xmax - xmin) / 20, y = (ymax - ymin) / 20)
Example Output:
Compression: CWS
Version: 10
Compressed Size: 166608
Dimensions: 200x100
精彩评论