views:

2367

answers:

5

I have a swf with loads text into a Sprite that resizes based on the content put into - I'd like though for the ones that are longer than the page to have the browser use its native scroll bars rather than handle it in actionscript (very much like http://www.nike.com/nikeskateboarding/v3/...)

I did have a look at the stuff nike did but just wasn't able to pull it off. Any idea's?

+1  A: 

I've never done it that way around but I think swffit might be able to pull it off.

grapefrukt
SWFFit is nice, but the latest version requires SWFObject, btw.
Ross Henderson
A: 

I halfway looked at swffit but the height (and width sometimes but mainly height) would be dynamic - swffit let's you declare a maxHeight but that number would be constantly changing...maybe I could figure out how to set it dynamically. A great place for me to start though - thanks!

onekidney
A: 

What I've mostly been using if for is to limit how small you can make a "fullbrowser" flash, and for that it works great. Happy hacking!

(and don't forget to post your findings here, I might need that too soon ;))

grapefrukt
+5  A: 

The trick is to use some simple JavaScript to resize the Flash DOM node:

function resizeFlash( h ) {
    // "flash-node-id" is the ID of the embedded Flash movie
    document.getElementById("flash-node-id").style.height = h + "px";
}

Which you call from within the Flash movie like this:

ExternalInterface.call("resizeFlash", 400);

You don't actually need to have the JavaScript code externally, you can do it all from Flash if you want to:

ExternalInterface.call(
    "function( id, h ) { document.getElementById(id).style.height = h + 'px'; }",
    ExternalInterface.objectID,
    400
);

The anonymous function is just to be able to pass in the ID and height as parameters instead of concatenating them into the JavaScript string.

I think that the JavaScript is fairly cross-platform. If you want to see a live example look at this site: talkoftheweather.com. It may not look as though it does anything, but it automatically resizes the Flash movie size to accommodate all the news items (it does this just after loading the news, which is done so quickly that you don't notice it happening). The resize forces the browser to show a vertical scroll bar.

Theo
I find I can get the width, but not set it.
Magnus Smith
I'm now sitting the SWF inside a DIV and resizing the DIV instead.
Magnus Smith
And set the swf to 100% of the div, so the swf will expand with the div.
adamcodes
A: 

SWFSize http://chargedweb.com/swfsize/samples/flash/

Intuitsolutions.ca

Nick