Recent News

flash full browser with swfObject 2

Posted by sortofme on July 9th, 2008

Having had difficulties to find a rather complete description on this very common subject, I thought I might as well compile a selection of techniques necessary to accomplish this.

first, let's go through the requirements within the HTML page and the swfObject javascript, which comes into the head of the HTML page embedding the swf:
more about the use of the swfObject here-->

HTML:
  1. <script type="text/javascript" src="js/swfobject.js"></script>
  2.     <script type="text/javascript"> 
  3.         //vars and parameters for embedded swf
  4.         var flashvars = { };
  5.         var params = { menu: "false", allowScriptAccess:"sameDomain", allowfullscreen :"true"};
  6.         var attributes = { id: "main", name: "main" };
  7.         swfobject.embedSWF("flash/main.swf", "mainFlash", "100%", "100%", "9.0.0","expressInstall.swf", flashvars, params, attributes); 
  8.     </script>
  9. <style type="text/css">
  10. <!--
  11.   html, body, #mainFlash{ height:100%; width:100%;}
  12.   body { margin:0; padding:0; overflow:hidden; background-color:#A31724; text-align:center; }
  13. -->
  14. </style>

    Set both the width and height of your SWF to 100% in your SWFObject definition.
    Include CSS to get rid of any default margins/padding and set the height of the html element, the body element and the entire chain of block level HTML elements that your SWF will be nested in to 100%, because Firefox (or: any Gecko based browser) in standards compliant mode (or: using a valid DOCTYPE) interprets percentages in a very strict way (to be precise: the percentage of the height of its parent container, which has to be set explicitly)

Now go to your flash movie, and manage the scaling and alignment of your SWF and the positioning of your SWF's elements, within your ActionScript code, e.g.:

Actionscript:
  1. stage.scaleMode = StageScaleMode.NO_SCALE;
  2. stage.align = StageAlign.TOP_LEFT;
  3.  
  4. stage.addEventListener(Event.RESIZE, resizeHandler);
  5.  
  6. function resizeHandler(event:Event):void {
  7.    trace(stage.stageWidth + " x " + stage.stageHeight);
  8.   // center stuff
  9. }

Flash and JavaScript

Posted by sortofme on April 21st, 2008

I will here collect a series of links of useful information on the interaction between flash and JavaScript, Until I have evaluated all relevant infos, to write a good summary on common practices.

  • SWFObject has grown up! version 2.0
    • static
    • dynamic
  • The famous SWFObject to easily embed flash content in html, that was previously hosted on deconcept.com has now moved to google.code basically there are 2 ways to embed your swf into your HTML site:

    Following is a basic code sample for the integration using swf object, including parameters, flashvars and attributes. (for many external interface interactions, you will need to give your swf an ID and a name)
    here the javascipt to embed, in this case for a fullBrowser embed of the swf:

    
    
    JavaScript:
    1. <script src="js/swfobject.js" type="text/javascript"></script>
    2. <script type="text/javascript">
    3.  
    4.         //vars and parameters for embedded swf
    5.         var flashvars = {var1:"sampleImg.jpg", var2:"my caption here"};
    6.         var params = { menu: "false", allowScriptAccess:"sameDomain",allowfullscreen :"true"};
    7.         var attributes = { id: "mainSwf", name: "mainSwf" };
    8.         swfobject.embedSWF("flash/main.swf", "mainSwfDiv", "100%", "100%", "9.0.0","expressInstall.swf", flashvars, params, attributes);
    9. </script>
    10. <!-- later in the html page comes the div tag where you want your swf to be embedded where you can put in your alternative text, in case someone has javascript disabled, or no flash plugin installed.-->
    11. <div id="mainSwfDiv">
    12.  You need Javascript activated and the flash player plugin installed to be able to view this content.
    13. The newest Flash Player can be downloaded here:
    14.  
    15. <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></div>

    Attention!!:
    giving the id or the name identical name to the swf file causes javascript errors on IE!! took me ages to find the reason for these. So just call your id and name differently than your swf is called.

  • Passing variable from JavaScript To AS3
  • A brief and basic recollection about passing vars from JS to AS3. found on: metah.ch

    <updated 04.08.2008>

    After having passed on variables inside of the swfObject script in my HTML/PHP page:

    Actionscript:
    1. //in the HTML:
    2. var flashvars = {var1:"sampleImg.jpg", var2:"my caption here"};
    3. // If you want to retrieve these vars later within your flash App:
    4. var myImagePath:String = this.loaderInfo.parameters.var1;
    5.  
    6. //to  trace all the variables (names and values) passed to the Flash Player:
    7. for ( var theName:String in this.loaderInfo.parameters ) {
    8.    var theValue:String = this.loaderInfo.parameters [theName];
    9.    trace("from JS :"+ theName+" "+theValue);
    10. }

    Read the rest of this entry »

    Recent Comments | Recent Posts


    designed and coded by: noesi
    bottom