views:

3764

answers:

6

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?

A: 

Did you try the accessing the following:

stage.stageWidth
stage.stageHeight


From the flash documentation:

If the value of the Stage.scaleMode property is set to StageScaleMode.NO_SCALE when the user resizes the window, the Stage content maintains its size while the stageHeight property changes to reflect the new height size of the screen area occupied by the SWF file. (In the other scale modes, the stageHeight property always reflects the original height of the SWF file.)

Ronnie Liew
unfortunately, as someone else named Matt pointed out, 'stage' refers to the root stage, not the stage of the loaded .swf
matt lohkamp
A: 

You must also wait until the external swf is FULLY LOADED otherwise the _width and _height properties will be 0.

eric
I'm sorry, I should've made the fact that this is AS3 more explicit.
matt lohkamp
+6  A: 

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.

Thanks for the tip on the 'stage' attribute - it's kind of counterintuitive, isn't it?
matt lohkamp
nice one! This totally works! It never occured to me to look at the loader info object - I usually just use a throwaway variable to hold it while I'm waiting for the 'real' content to load, but I might try and keep it around in the future... thanks!
matt lohkamp
shit, even better, you can just say myMovieClip.loaderInfo.width, instead of having to keep the original swfLoader around in another variable - anything loaded through Loader keeps a reference back to its own Loader object!
matt lohkamp
+1  A: 

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.

James Fassett
I had to do a quick fix and didn't have time to check out Matt's answer, and my quick fix was your suggestion - I made two MovieClips inside the loaded .swf, one that matched the dimensions of the stage, and one that surrounded and exceeded the boundaries created by the elements breaking the stage.
matt lohkamp
A: 

Hi Matt, Thanks for your tip, it greatly helped me :)

Thanks,

Naresh

Naresh
A: 

You can not imagine how much help the contentLoaderInfo.width helped me. Very appreciated!!!

All excited!

cafeine
You're welcome - you can additionally call this.loaderInfo from inside of a loaded .swf to get the same 'default' stage dimensions.
matt lohkamp