1 Reply Latest reply on May 3, 2009 6:49 PM by Nick Belaevski

    How to embed Flash with outputMedia ?

    adam kanicki Newbie

      I want to embed Flash.swf on my jsf page. I'm using jsf,facelets,RichFaces and I don't know how to embed flash movie on my page.

        • 1. Re: How to embed Flash with outputMedia ?
          Nick Belaevski Master

          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();
           }
           }
           }