bjornson’s blog

this blog is very young, come again to watch it grow

Archive for the ‘HTML’ tag

AS3 + JavaScript = Resizable SWF in HTML

with 8 comments

I recently needed to resize an swf dynamically within an HTML document and could decided to combine JavaScript with AS3. So here is my solution in three simple steps:

  1. I wrote a simple JavaScript file that allows resizing of elements in an animated fashion.
  2. I embedded the swf in the HTML file in a <div> container with the style attribute “overflow:hidden;” and an id called “swf_container”.
  3. To ensure the desired effect I added stage.scaleMode = StageScaleMode.NO_SCALE; stage.align = StageAlign.TOP_LEFT;
  4. Now I added a button in the Flash file that caused navigateToURL(new URLRequest(“JavaScript:sizeById(‘swf_container’,500,150,5)”), “_self”); and with this calling the JavaScript function and resizing itself.

If you want to try this yourself you can download the JavaScript file sizebyid.js and recreate what I did with it or download the whole including the -.Fla, the -.swf, the -.js and the -.html file.

Of course you can try it out first:

Click the arrow in the top left corner to toggle sizes of the sample.

You can also use the following html form that calls the same JavaScript function

px width
px height
steps (fewer steps=faster)

Written by bjornson

November 5th, 2008 at 7:41 pm