This is usually the last step, but knowing how to do it properly will save you time, seriously.
For the examples, I’m creating a 400×300px Flash file, with Stage colored gray, and a rectangle of a darker gray. As for the reason why, you would see in the following.
1. The normal Flash export way : See the demo
If you do File -> Publish, Flash would export a HTML file along with your SWF by default. But it would result in 300+ lines of code. They are used to detect the Flash version, embedding, and a whole lot of handling events.
I would say that you should go with it if you don’t have even 10 minutes for proper embedding.
2. SWFObject : SWFObject home page
Why SWFObject :
- It requires less hand-coding on your side
- It’s flexible in detecting Flash version, installer file and such
- You can tell the browser to display alternate content when Flash is not there (which is an important factor for SEO content and search bot crawling)
Here are some basic examples of SWFObject that you can use :
2.1 Normal way with alternate content :
Demo
In your HTML head, remember to include your swfobject javascript :
<script type="text/javascript" src="swfobject.js"></script>
Then create a <div> with an id to hold your SWF. You can add any content in this div, and it would be displayed when there’s no Flash (and read by search bots)
<div id="divID">
<p>Alternative content</p>
</div>
Then place a javascript script to embed it
var flashvars = {};
var params = {};
var attributes = {};
swfobject.embedSWF("myContent.swf","divID","300", "120", "9.0.0","expressInstall.swf", flashvars, params, attributes);
The syntax is :
swfobject.embedSWF(“flash_file_name.swf”, “div_id”, “width”, “height”, “flash_version”, “express_install_file”, flashvars, params, attributes);
*express_install_file is displayed if the Flash version is not the current one, it’s included in the SWFObject zip file download
* the last 3 parameters (flashvars, params, attributes) are optional
2.2 Full browser Flash:
Demo 1 (Scaled)
Sometimes, you would want to make your Flash expand with the browser windows, and you would need to include some CSS in your HTML.
In default case (no Stage controlled with Actionscript), all of the content on your stage will be centered, with your stage color as the background when the browser is expanded.
The CSS that you would need :
body,#divid{
height:100%;
}
And in your embed :
swfobject.embedSWF("flash_file_name.swf", "divID", "100%", "100%", "9.0.0", "express_install_file", flashvars, params, attributes);
But know that it would scale your Flash along with the browser.
Demo 2 (Not scaled)
If you don’t want your Flash to be scaled with your browser, you would need to include this line in your FLA file :
stage.scaleMode = "noScale";
Then export it again, and see the difference.
(To be continued – complex Stage position and content floating with browser window in next post)