Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I resize a swf during runtime to have the browser create html scrollbars?

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?

like image 406
Paul Mignard Avatar asked Aug 28 '08 17:08

Paul Mignard


2 Answers

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.

like image 118
Theo Avatar answered Sep 20 '22 12:09

Theo


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

like image 33
grapefrukt Avatar answered Sep 22 '22 12:09

grapefrukt