Arion
Arion

Reputation: 1880

Get the Embedded Width/Height of a Flash Player using AS3

I'm using swfobject to embed an swf into a web page.

var params = {};
params['movie'] = 'player.swf'; 
params['wmode'] = 'transparent'; 
params['bgcolor'] = 'ffffff';
params['allowScriptAccess'] = 'always'; 
params['allowFullScreen'] = 'true'; 

var flashvars = {};
flashvars['url'] = 'video.flv';
flashvars['resize'] = 'fit-player';
swfobject.embedSWF("player.swf", "video", "480", "340", "10.1.0", null, flashvars, params);

Which creates the following HTML (I'm testing in FF3.6, so the actual HTML may vary a bit depending on your browser, but it should be close enough):

<object width="480" height="340" type="application/x-shockwave-flash" data="EmbeddedPlayer.swf" id="video" style="visibility: visible;">
    <param name="wmode" value="transparent">
    <param name="bgcolor" value="ffffff">
    <param name="allowScriptAccess" value="always">
    <param name="allowFullScreen" value="true">
    <param name="flashvars" value="url=MD-Open_ProblemOne_1000k_part2.flv&amp;resize=fit-player">
</object>

I'm trying to find a good way of getting the 'width' and 'height' attributes from within AS3. stage.stageWidth returns the width that was defined in CS5, stage.width returns the width of the combined dimensions/positions of its children, and LoaderInfo(this.root.loaderInfo).width throws the following error:

Error: Error #2099: The loading object is not sufficiently loaded to provide this information.

Any help would be greatly appreciated!

Upvotes: 1

Views: 3532

Answers (2)

Adam Harte
Adam Harte

Reputation: 10510

Just use stage.width and stage.height. These return the full width and height of the embedded flash, rather than the stage's width and height set in flash.

Upvotes: 2

Eugeny89
Eugeny89

Reputation: 3731

pass width from JS in flashvars:

....
var flashvars = {};
flashvars['url'] = 'video.flv';
flashvars['resize'] = 'fit-player';
flashvars['height'] = '340';
flashvars['resize'] = '480';
swfobject.embedSWF("player.swf", "video", "480", "340", "10.1.0", null, flashvars, params);

Upvotes: 0

Related Questions