In writing SWF Tools I attempted to follow some design patterns that would make the embedding aspect of it generic. The embedding logic is there, but it's surrounded by a lot of unreleted code. So with the benefit of hindsight, here is a run-through of an "Embed API". Much of this is simply cloned Forms API.
Simple declaration
Examples of defining an $embed.
<?php
$embed = array(
'#type' = 'application/x-shockwave-flash',
'#object' => 'files/mp3player.swf',
);
?>#types
The #type property above is a long explicit format, and I don't think that format will stick because "application/x-ms-wmv" makes a pretty poor callback name. So a set of simple types would be preferable. Some examples are: "flash", "wmv", "quicktime", "svg", "pdf", "msword"...
<?php
$embed = array(
'#type' = 'wmv',
'#object' => 'files/myhotmovie.wmv',
);
?>#properties
Just as with FAPI types, some properties are only relevant to some types.
<?php
$embed = array(
'#type' = 'quicktime',
'#object' => 'files/MacVsPC.mov',
'#params' => array(
'width' => 400,
'height' => 300,
);
);
?><?php
$embed = array(
'#type' = 'flash',
'#object' => 'files/myflashplayer.swf',
'#flashvars' => array(
'hovercolor' => '#123456',
'autostart' => TRUE,
'file' => 'http://example.com/files/turnerandhooch2.flv',
);
);
?>Usage
Clearly, embedding is not as complex as FAPI and we see a
number of differences. Here an an example of using the API to display a file.
drupal_get_form() is not needed here.
<?php
$embed = array(
'#id' => 'my_cool_game',
'#type' = 'flash',
'#object' => 'files/mycoolgame.swf',
);
print embed_render($embed);
}
?>Altering $embed
Some embed_alter sugar for fairly obvious reasons, some yet to be discovered.
<?php
function mymodule_embed_alter(&$embed) {
switch ($embed['#type']) {
case 'flash':
$embed['#flashvars']['veryobscure'] = 'dothehokeypokey';
}
}
?>Rendering methods
Prior to theming, we may want some display variations. Taking the example of a swf file, we have the old-skool <object> embedding,
and should consider this the default. However an alternative would be a custom "flash replacement technique" (eg swfobject, ufo) instead:
<?php
$embed = array(
'#id' => 'my_cool_game',
'#type' = 'flash',
'#object' => 'files/mycoolgame.swf',
'#method' => 'swfobject' // <-- embedding with swfobject javascript
);
print embed_render($embed);
function embed_flash_swfobject($embed) {
// Code to include swfobject.js and out put the html
drupal_add_js('swfobject.js', ...);
$output = ...
return $output;
}
?>Only after the embedding code has been generated do we theme it.
<?php
function theme_my_cool_game($rendered_embed) {
return "<div>". $rendered_embed ."</div>";
}
?>Other notes
The actual code is not an issue. I'm ready to create a DRUPAL-5--2 version of SWF Tools that uses Embed API as a dependency, and this involves little more than splitting up swftools.module.
Another plan is include with the Embed API the common #method variations (swfobject, ufo, qtobject) as .inc files that ship with the module. This should make it a nice lightweight option for the various embedding modules out there.
Any thoughts?

Comments
hook_elements
I'd like to use hook_elements, but wonder about future namespace issues... hence example below prefixes type with 'embed_'
<?php/**
* Implementation of hook_elements().
*/
function embed_elements() {
// Use a separate namespace by using an 'embed_' prefix.
$type['embed_flash'] = array('#input' => FALSE, '#doctype' => 'application/x-shockwave-flash', '#flashvars' => array(), '#params' => array(), '#method' => 'default';
$type['embed_quicktime'] = array('#input' => FALSE, '#doctype' => 'video/quicktime', '#params' => array(), '#method' => 'default');
$type['embed_pdf'] = array('#input' => FALSE, '#doctype' => 'pdf', '#method' => 'default');
$type['embed_svg'] = array('#input' => FALSE, '#doctype' => '...', '#method' => 'default');
return $type;
}
?>
swx
Have you looked at Aral Balkan's swx? Do you have any interest in it as a tool for Flash remoting? Will it integrate easily into Drupal via services - do you know? (It's still in beta, I know...)
I am interested in using it because it is easy from a Flash perspective; my php coding is not up to much.
Well
I can't think of any useful ideas right now but it was an interesting post and it will be interesting to see how you continue working on it.
Douglas, Programmer currently working on the how to loose 40 pounds project.
Douglas, Programmer currently working on the how to loose 40 pounds project.