I have an ActionScript project set up using the Flash Builder IDE. Using the Flex 4 compiler to compile it. At the top of my application class, I have:
[SWF(width="100%", height="100%")]
public class MediaPlayer extends MovieClip {
This is not acceptable to the compiler to do a release (it throws errors saying it can't parse the width/height values). Pretty annoying. I've tried to do things the "right" way, but none of the following work:
[SWF(percentWidth="100%", percentHeight="100%")]
[SWF(percentWidth="100", percentWidth="100")]
[SWF(widthPercent="100%", heightPercent="100%")]
[SWF(widthPercent="100", heightPercent="100")]
When I use any of those, the stageHeight is 375 (the Flex default) and stageWidth is 500 (default). What is the proper way to do this?
My flash files are being embedded on the web, and I just need the width and height attributes defining the bounds of the flash content to be respected by the SWF.
UPDATE To give a little more context, I don't have control over how this SWF is embedded - it is handled by Facebook code for their in-st开发者_运维知识库ream media content.
<div id="u162171_43" style="width:398px;height:259px">
<iframe width="398" height="259" frameborder="0" src="https://s-static.ak.facebook.com/common/referer_frame.php">
<body style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">
<embed type="application/x-shockwave-flash" src="http://www.rootmusicd.com/flash/fb/rm_player.swf?v=140&d=www.rootmusicd.com&id=102199429820702" width="398" height="259" style="" id="swf_u187610_44" name="swf_u187610_44" bgcolor="#FFFFFF" quality="high" scale="scale" allowfullscreen="true" allowscriptaccess="never" salign="tl" wmode="opaque" flashvars="bridge_connection_id=_conn_4d9b46f8c10ea6089493440&payer_connection_id=_payer_4d9b46f8c10f64d23500210&width=398&height=259">
</body>
</iframe>
</div>
So the width and height attributes are being explicitly set to numbers here. I don't know much about the 'scale' attribute; maybe it is coming in to play here? And, to be clear: it will work as expected if I set the [SWF] meta tag to have width "100%" and height "100%"... so it seems like it actually is preferring the compiled arguments over the browser environment. Perhaps there are other settings I am missing?
Short answer: set the size you want in the web page where you embed the SWF, rather than in the AS source.
Full answer: As metadata, the width and height that get compiled into a SWF are essentially suggestions. When the SWF is displayed, its size is wholly decided by its container, so the only time the metadata gets honored is if the container chooses to read and honor it. Generally, they only container that does that is the standalone player - thus if you double-click the SWF it should launch at the size you specified in the source. But when you display the SWF embedded in a web page, the width/height metadata gets ignored entirely, and the SWF's size is determined similarly to all the other elements in your page (by the embedding HTML, CSS, and so on).
That's all slightly beside the question of why the metadata doesn't take percentages, but hopefully it makes more sense in this context... and since the metadata doesn't affect what happens in a browser, it's a bit academic. I can't answer for how percentWidth
etc. fit into things, as it doesn't seem to be documented, but I assume that setting those values doesn't affect the SWF's size in a browser either (unless of course FlashBuilder is generating HTML based on the metadata, or something fancy like that - I'm not too up on FB).
Update
I think I see your problem here. We need to back up a bit and talk about scaling. Any time the size of a SWF differs from the size of its viewport (i.e. the size allotted to Flash by its container), Flash makes a decision about how to scale the content, depending on the stageScaleMode. The details of the four scale options are described in that link, but basically the content is left unscaled, or it's scaled up or down in such a way as to preserve, or not preserve, aspect ratio.
However, in order for Flash to know whether/how to scale the content, the content must have an "intrinsic" size. The height/width metadata we've been talking about is used as that size. So if your HTML container is 200x400 and you use the "exact fit" scalemode, then if your metadata describes a size of 100x200 your content will display at double size, and if your metadata said 400x800, the SWF will show up at half size. If you use the "no scale" scalemode, then your metadata will not affect the content's scaling. (Content still gets aligned within the container according to stageAlign.)
Taking the previous into account, I hope it will be clear that the "correct" value to use for your size metadata depends on what kind of scaling you use and how your content will adapt (or not adapt) to different sized containers. If your content is laid out statically within a 259x398 area, then 259x398 is the proper metadata size to use. That way, if you were to view it in a larger container, your content would be scaled up as one would expect, depending on scale mode. However, if your content dynamically adjusts to variably-sized containers, and automatically lays out its content at runtime, then you almost certainly need to use "no scale" mode - in which case it doesn't matter very much what size metadata you use, so the flex default size should work fine.
Incidentally, scale mode can be defined in the HTML embed parameters, but you can also override that setting at runtime. So work out what scale mode meets your needs, and set that mode before your content initializes, and then you should be able to find a metadata size that works.
Set your SWF tag to the proper aspect ratio in pixels and then use 100% as your width and height in the embed code on your page
swfobject.embedSWF('foo.swf', 'bar', '100%', '100%', '9');
精彩评论