Trent Wyman


Top Navigation

Embed Flash into web page using SWF Object


Below are the scripts I use to embed a Flash file into a web page or Drupal node tpl file using SWF Object. Examples include using JW Player for rtmp & flv streaming. Also a basic SWF Object script to load single .swf or .flv file into a web page.
-----------------------------------------------------

Example 1: Load Streaming Video into SWF Object (using JW Player)

<div id="flashContain">
<!-- Text to display if user does not have Flash Installed -->
In order to view this video, you need to download and install the latest version of Adobe Flash Player. Follow these steps to download and install the player:
1. Bookmark this web page
2. Go to <a href="http://get.adobe.com/flashplayer/" alt="Get Flash Player" title="Get Flash Player" target="_blank">http://get.adobe.com/flashplayer/</a> and follow the instructions
3. Re-open your browser and return to this bookmarked page

<?php $streamurl = 'rtmp://edge01.fms.dutchview.nl/botr'; ?>

<script type='text/javascript' src='<?php print base_path(); ?>sites/all/files/js/swfobject.js'></script>

<script type='text/javascript'>
var s1 = new SWFObject('<?php print base_path(); ?>sites/all/files/swf/player.swf','player','340','240','9');
s1.addVariable('allowfullscreen','false');
s1.addVariable('allowscriptaccess','always');
s1.addVariable("wmode", "transparent");
s1.addVariable("type", "rtmp");
s1.addVariable("bufferlength", "0");
s1.addVariable("subscribe", "true");
s1.addVariable("autostart", "true");
s1.addVariable('file','<?php print $streamurl; ?>');
s1.write('flashContain');
</script>

</div><!-- End "flashContain" DIV -->

--------------------------------------------------------------

Example 2: Load a single .swf file into SWF Object (without JW Player)

<div id="flashContain">
<!-- Text to display if user does not have Flash Installed -->
In order to view this video, you need to download and install the latest version of Adobe Flash Player. Follow these steps to download and install the player:
<br />
1. Bookmark this web page
2. Go to <a href="http://get.adobe.com/flashplayer/" alt="Get Flash Player" title="Get Flash Player" target="_blank">http://get.adobe.com/flashplayer/</a> and follow the instructions
3. Re-open your browser and return to this bookmarked page

<script type='text/javascript' src='<?php print base_path(); ?>sites/all/files/js/swfobject.js'></script>

<script type="text/javascript">
var so = new SWFObject("<? print base_path().path_to_theme().'/swf/filenamehere.swf' ?>", "moviename", "340", "240", "9");
so.addParam("salign", "t");
so.write("flashContain");
</script>

</div><!-- End "flashContain" DIV -->

------------------------------------------------------------------

Example 3: Load a single .flv file into SWF Object (using JW Player)

<div id="flashContain">
<!-- Text to display if user does not have Flash Installed -->
In order to view this video, you need to download and install the latest version of Adobe Flash Player. Follow these steps to download and install the player:
1. Bookmark this web page
2. Go to <a href="http://get.adobe.com/flashplayer/" alt="Get Flash Player" title="Get Flash Player" target="_blank">http://get.adobe.com/flashplayer/</a> and follow the instructions
3. Re-open your browser and return to this bookmarked page

<script type='text/javascript' src='<?php print base_path().path_to_theme();?>/js/swfobject.js'></script>

<script type='text/javascript'>
var s1 = new SWFObject('<?php print base_path().path_to_theme();?>/swf/player.swf','player','340','240','9');
s1.addParam('allowfullscreen','true');
s1.addParam('allowscriptaccess','always');
s1.addParam('flashvars','file=<?php print base_path().path_to_theme();?>/flv/filenamehere.flv');
s1.write('flashContain');
</script>

</div><!-- End "flashContain" DIV -->

-------------------------------------------------------------------

Example 4: Load a single .swf file without using SWF Object (standard embed method)

<object height="240" width="340" data="/sites/default/files/filenamehere.swf" type="application/x-shockwave-flash">
<param name="scale" value="exactfit" />
<param name="salign" value="t" />
<param name="wmode" value="transparent" />
<param name="src" value="/sites/default/files/filenamehere.swf" />
</object>

--------------------------------------------------------------------

RESOURCES:

SWF Object = http://code.google.com/p/swfobject/
JW Player = http://www.longtailvideo.com/players/
Setup Wizard = http://www.longtailvideo.com/support/jw-player-setup-wizard?example=4

AttachmentSize
swfobject.js6.72 KB
player.swf41.57 KB
AC_RunActiveContent.js.txt7.84 KB