Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Additional params for uploaded flash


Go to End


23 Posts   7122 Views

Avatar
AlaVive

Community Member, 42 Posts

20 November 2009 at 10:06am

Edited: 20/11/2009 11:59am

Is there a way to add additional default parameters, such as wMode: transparent, to the content flash upload?

Edit: Sorry for the lame way of asking, but I am in 2.3.3 and need to add the "wMode: transparent" to all flash files uploaded through the HTML editor for a page content region. Any help?

Thanks!

Avatar
dalesaurus

Community Member, 283 Posts

26 November 2009 at 4:52am

Do you mean for the corresponding embed, or do you want to store a wMode attribute with the file metadata to be used later?

Avatar
AlaVive

Community Member, 42 Posts

26 November 2009 at 8:15am

Thanks for responding, dalesaurus. And, please forgive my density if I'm not answering the question correctly.

I need all flash files uploaded through the content area of the CMS to have the wMode: transparent attribute associated with the corresponding embed.

The following is what shows in source by default:

<object height="342" width="613" type="application/x-shockwave-flash" data="assets/Flash/dMap_v6_aa.swf">
<param value="assets/Flash/dMap_v6_aa.swf" name="src"/>
</object>

If I upload through a custom field, I know I can code it within the layout (or, at least I think I can). But, I didn't want to go that way (adding any additional fields in the CMS for this) if I could just modify what's already in place.

It may sound silly, but is there a way to deal with this through CSS?

Does this make sense? (I'm fighting some kind of ick at the moment and don't trust my powers of communication.)

Avatar
dalesaurus

Community Member, 283 Posts

26 November 2009 at 11:28am

I see what you're up to and it does make sense. However without digging in the code I don't think there is a way to change the embed without hacking some core files. You can do that OR be really lazy and hammer at it with jQuery.

Avatar
bummzack

Community Member, 904 Posts

26 November 2009 at 8:27pm

Edited: 26/11/2009 8:27pm

Hi AlaVive

I think it would be best to separate the flash content in a file upload field and then use SWFObject to embed the flash. This approach has several advantages:
- You can freely customize all the flash embed parameters and more
- SWFObject automatically detects if the required flash player is installed and can otherwise display alternative content
- It generates valid HTML

The jQuery hack proposed by dalesaurus could be another option, but I'm not sure if it will work. My guess is, that the Flash Player Object only checks the wmode parameter at initialization. Now if that happens before jQuery runs, you're out of luck. But it's probably worth a try.

Personally, I would choose the SWFObject route and even add a text-field along the file upload field to my page, so that I could provide some alternative text for that flash content (for google, and all the users that don't have flash installed).
If that sounds like a good idea to you, I'd be happy to provide you with a code example.

Avatar
AlaVive

Community Member, 42 Posts

27 November 2009 at 4:13am

Thanks again for your thoughts, dalesaurus.

Banal, thank you, as well, for your points. You've convinced me. So, if you still don't mind sharing, I am interested in seeing a code example you offered!

Avatar
bummzack

Community Member, 904 Posts

27 November 2009 at 5:47am

Sure thing.

Prerequisites
- Download and unpack swfobject 2.2 from http://code.google.com/p/swfobject/
- copy swfobject.js and expressInstall.swf from the swfobject folder to your mysite folder. I copied the files into mysite/javascript/lib, so this is what I'm gonna use in this example

I suggest to create a special Page class for our needs. Let's call it "FlashPage". Copy the following code to a file named FlashPage.php in mysite/code:

<?php
class FlashPage extends Page 
{
	public static $db = array(
		'AlternateContent' => 'HTMLText'
	);
	
	public static $has_one = array(
		'FlashFile'	=> 'File'
	);
	
	public function getCMSFields(){
		$fields = parent::getCMSFields();
		
		// create a file upload field that only allows swf to be uploaded
		$fileUpload = new FileIFrameField('FlashFile', 'Flash file (swf)');
		$fileUpload->setAllowedExtensions(array('swf'));
		
		$fields->addFieldsToTab('Root.Content.Flash', array(
			$fileUpload,
			new HtmlEditorField('AlternateContent', 'Flash replacement text', 20)
		));
		
		return $fields;
	}
}

class FlashPage_Controller extends Page_Controller
{
	public function init(){
		parent::init();
		// require SWF Object script
		Requirements::javascript('mysite/javascript/lib/swfobject.js');
	}
}

After doing this, run dev/build

The FlashPage class has a FlashFile and an alternative content that will show if the flash player isn't installed on the visitors machine. I added these two fields to a new Tab called "Flash" on the same level as "Main".

Now you only need a template for the FlashFile page. This could be either a layout or a full page template. Here's the important template code:

<% if FlashFile %>
<div id="FlashContainer">
	$AlternateContent
</div>
<script type="text/javascript">
/* <![CDATA[ */
swfobject.embedSWF(
	"$FlashFile.URL", 
	"FlashContainer", 
	"400", "300", 
	"9.0.0", 
	"mysite/javascript/lib/expressInstall.swf", 
	null,
	{ 'bgcolor' : '#000000', 'wmode' : 'transparent' }
);
/* ]]> */
</script>
<% end_if %>

Here's a short summary what we do here:
First we check if there's a FlashFile available (<% if FlashFile %>). If not, we can skip the whole flash embed stuff.
The <div id="FlashContainer"> container holds the alternative content, and will be replaced with the flash content if the user has the required flash plugin installed.
What follows at the end is the script call to swfobject. There's a good description of these parameters on the SWFObject website:
http://code.google.com/p/swfobject/wiki/documentation#STEP_3:_Embed_your_SWF_with
The wmode can be set with the params argument as I did in the example (I also set the background color).

Let me know if that works :)

Avatar
Taffy

Community Member, 119 Posts

28 November 2009 at 12:55am

Banal: Might be worth chucking this up on SSbits.com :)

Go to Top