Archive for the ‘AS3’ tag
AS3 + JavaScript = Resizable SWF in HTML
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:
- I wrote a simple JavaScript file that allows resizing of elements in an animated fashion.
- I embedded the swf in the HTML file in a <div> container with the style attribute “overflow:hidden;” and an id called “swf_container”.
- To ensure the desired effect I added stage.scaleMode = StageScaleMode.NO_SCALE; stage.align = StageAlign.TOP_LEFT;
- 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 sample.zip 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
