home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2012 January / ME_2012_01.iso / Galileo-Video / system / js / flash_ex_int.js < prev    next >
Encoding:
Text File  |  2007-10-07  |  2.2 KB  |  88 lines

  1. function FlashInterface ( swf_id )
  2. {
  3.     if ( SWFObject != null )
  4.     {
  5.         if ( swf_id instanceof SWFObject )
  6.         {
  7.             var allowScriptAccess = String ( swf_id.getParams()['allowScriptAccess'] ) . toLowerCase ();
  8.             if ( allowScriptAccess != 'always' )
  9.             {
  10.                 alert ('You have to define alloScriptsAcces - otherwise the Flash ExternalInterace does not work \n yourSWFobject.addParam(\"allowScriptAccess\", \"always\")');
  11.             }
  12.             swf_id = String ( swf_id.getAttribute('id') );
  13.         }
  14.     }
  15.     if ( navigator.appName.indexOf ("Microsoft") != -1 )
  16.         this.flashMovie = window[swf_id]
  17.     else
  18.         this.flashMovie = document[swf_id];
  19.         
  20.     if (this.flashMovie == undefined )
  21.     {
  22.         //alert (" could not work without Movie " );
  23.         return null;
  24.     }    
  25. }
  26.  
  27. FlashInterface.prototype.callAS = function ()
  28. {
  29.     var params = new Array();
  30.     for (var i=0; i<this.callAS.arguments.length; i++)
  31.             params.push ( this.trimAndMakeTypeSave ( this.callAS.arguments[i] ) );
  32.     var as_func_name = this.trim ( params.shift () );
  33.     var outPut;
  34.     if ( this.flashMovie[as_func_name] == null ||  this.flashMovie[as_func_name] == undefined )
  35.     {
  36.         var outPut = "The AS function:= " + as_func_name + " you try to connect does not exist or is not\nregistered ExternalInterface_netTrek.addCallback ( " + as_func_name + ", callBackObj, callBackFct);";
  37.         alert ( outPut ); 
  38.     } 
  39.     else
  40.     {
  41.         outPut = this.flashMovie[as_func_name] (params) ;
  42.     }
  43.     return( outPut ) ;
  44. }
  45.  
  46. FlashInterface.prototype.trim  = function  ( str )
  47. {
  48.     if ( str == null || typeof str != 'string')
  49.     {
  50.         return str;    
  51.     }
  52.     var a = 0;
  53.     while ( str.charCodeAt ( a ) == 32 )
  54.     {
  55.         a++;
  56.     }
  57.     str = str.substr ( a );
  58.     a = str.length - 1;
  59.     while ( str.charCodeAt ( a ) == 32 )
  60.     {
  61.         a--;
  62.     }
  63.     
  64.     return ( str.substr ( 0, a + 1 ) );
  65. }
  66.  
  67.  
  68. FlashInterface.prototype.trimAndMakeTypeSave = function ( cArg )
  69. {
  70.     switch (typeof cArg) {
  71.       case "string":
  72.             cArg = this.trim (cArg);
  73.             if ( cArg.toLowerCase()==='true')
  74.                 cArg = true;
  75.             else if ( cArg.toLowerCase()==='false')
  76.                 cArg = false;
  77.             else if ( !isNaN ( Number ( cArg ) ) )
  78.                 cArg = Number ( cArg );
  79.         break;
  80.       case "number":
  81.       case "boolean":
  82.       default:
  83.         break;
  84.     }
  85.     return cArg;
  86. }
  87.  
  88.