The other day I wanted to edit the html wrapper that Flash Builder generates for the swf – so that it centres any swf both horizontally and vertically without applying the Flash/Flex Builder default scaling.
After some tinkering, going back and looking at my Flashdevelop html templates for the I found that what I usually do to center an swf with swfObject is write some CSS:
#divFloat {
position:absolute;
top:50%;
left:50%;
right:50%;
bottom:50%;
margin:-300px; /* Half the height of your SWF*/
margin-left:-400px; /* Half the width of your SWF*/
}
</style>
To get this to work all that is needed is a div with the matching id ‘divFloat’ added to the html body of the html page that acts as a wrapper for the swf; and this will centre the swf vertically and horizontally. (A more old school approach would be using nested tables…)
Based on the CSS above we can device a similar approach and apply it to Flash Builder’s publishing method. The part to figure out is how to insert it into Flash Builders template based creation of the html wrapper.
To do so we must edit the index.template.html in the html-template folder in the Flash Builder project directory: which is the blueprint for the html file generated in the bin-debug folder.
In Flash Builder our html wrapper and swf will be based on what name we choose for our main application file (the one that initializes our application). This value is held by the variable ${application} in index.template.html. It is also the id of our embedded content in the html page that results in bin-debug, based on our index.template.
So we can write in index.template.html:
body { margin: 0px;}
#${application} {
position:absolute;
top:50%;
left:50%;
right:50%;
bottom:50%;
margin:-300px; /* Half the height of your SWF*/
margin-left:-400px; /* Half the width of your SWF*/
}
</style>
If our application class has the name ‘OrangeApp.as’ that will translate into #OrangeApp{ in the resulting html file in the bin-debug folder and target the id of the embedded swf so that the CSS is applied to centre it.
Of course the swf still needs to have the following code in it’s application class:
stage.align = StageAlign.TOP_LEFT
And we should also specify the width and height of the swf in the index.template.html as usual by just replacing ‘width’ and ‘height’ with the real width and height of our swf. That will center our html wrapped SWF in Flash Builder; and remove the pesky default ‘Flex scaling’ without too much work!

