This content has been marked as final.
Show 1 reply
-
1. Re: How to embed Flash with outputMedia ?
nbelaevski May 3, 2009 6:49 PM (in response to kanikman)Hello,
Here is an example of embedding SWF movie using SWFObject library:<a4j:loadScript src="resource:///org/richfaces/renderkit/html/js/swfobject.js" /> <a4j:outputPanel id="flashPanelDynamic"> <a4j:mediaOutput element="a" id="swfLink" style="display: none;" cacheable="false" session="true" createContent="#{mediaBean.paintFlash}" value="#{mediaData}" /> <a4j:outputPanel layout="block" id="myFlashContent" style="width: 200px; height: 200px"> <a href="http://www.adobe.com/go/getflashplayer"> <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /> </a> </a4j:outputPanel> <script type="text/javascript"> var flashvars = {}; var params = {}; var attributes = {}; swfobject.embedSWF(#{rich:element('swfLink')}.href, "#{rich:clientId('myFlashContent')}", "200", "200", "9.0.0", false, flashvars, params, attributes); </script> </a4j:outputPanel>
Code for paintFlash() method is very simple:private void copy(InputStream in, OutputStream out) throws IOException { byte[] buffer = new byte[2048]; int read; while ((read = in.read(buffer)) != -1) { out.write(buffer, 0, read); } } public void paintFlash(OutputStream out, Object data) throws IOException { ClassLoader loader = Thread.currentThread().getContextClassLoader(); if (loader == null) { loader = getClass().getClassLoader(); } InputStream stream = loader.getResourceAsStream("org/richfaces/demo/mediaoutput/text.swf"); if (stream != null) { try { copy(stream, out); out.flush(); } finally { stream.close(); } } }