Question

Here's the situation - I've got a shell that loads an external .swf. Now, that .swf is 800x600, but it's an animation piece, and there are elements that extends off the stage. When I load the .swf into the shell and call its width attribute, it returns 1200 - because it's including the elements that break out of the stage.

This isn't what I want - ideally, there would be two properties, one to return the 'calculated width' and one to return the 'default width'. Do these properties exist, and if not, what's the best workaround?

Was it helpful?

Solution

The width and height of the loaded SWF as defined by the FLA it was created with can be found in the Loader object in which you've loaded the SWF into.

swfLoader.contentLoaderInfo.width
swfLoader.contentLoaderInfo.height

This will always show you the dimensions as defined in the FLA properties. It makes no difference if any images, MovieClips, or what have you extend off the stage.

The stage.stageWidth and stage.stageHeight properties will always return the width of the stage, the stage is always the top most SWF. In other words, it will always represent the dimensions of the shell's stage. There is only ever one stage in a Flash application.

OTHER TIPS

Mark is very likely right that the content loader info object will contain the correct width and height. I've never checked myself so I can't guarantee it. The docs say 'nominal' and contrast it with 'actual' so it seems reasonable.

There are a couple of other options. You can mask the external swf. Create a mask that is the size of the stage and put all content underneath it. Another idea is to create a movieclip based on a rectangular shape set it's alpha to 0 place it at x:0, y:0 and match it's width and height to stage. Give it an instance name and then when it is loaded use that value for the size.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top