fullAvatarEditor.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. function fullAvatarEditor() {
  2. var id = 'fullAvatarEditor' //flash文件的ID
  3. var file = 'plugins/fullavatareditor/fullAvatarEditor.swf'; //flash文件的路径
  4. var version = "10.1.0"; //播放该flash所需的最低版本
  5. var expressInstall = 'expressInstall.swf'; //expressInstall.swf的路径
  6. var width = 600; //flash文件的宽度
  7. var height = 430; //flash文件的高度
  8. var container = id; //装载flash文件的容器(如div)的id
  9. var flashvars = {};
  10. var callback = function(){};
  11. var heightChanged = false;
  12. //智能获取参数,字符类型为装载flash文件的容器(如div)的id,第一个数字类型的为高度,第二个为宽度,第一个object类型的为参数对象,如此4个参数的顺序可随意。
  13. for(var i = 0; i < arguments.length; i++)
  14. {
  15. if(typeof arguments[i] == 'string')
  16. {
  17. container = arguments[i];
  18. }
  19. else if(typeof arguments[i] == 'number')
  20. {
  21. if(heightChanged)
  22. {
  23. width = arguments[i];
  24. }
  25. else
  26. {
  27. height = arguments[i];
  28. heightChanged = true;
  29. }
  30. }
  31. else if(typeof arguments[i] == 'function')
  32. {
  33. callback = arguments[i];
  34. }
  35. else
  36. {
  37. flashvars = arguments[i];
  38. }
  39. }
  40. var vars = {
  41. id : id
  42. };
  43. //合并参数
  44. for (var name in flashvars)
  45. {
  46. if(flashvars[name] != null)
  47. {
  48. if(name == 'upload_url' || name == 'src_url')
  49. {
  50. vars[name] = encodeURIComponent(flashvars[name]);
  51. }
  52. else
  53. {
  54. vars[name] = flashvars[name];
  55. }
  56. }
  57. }
  58. var params = {
  59. menu : 'true',
  60. scale : 'noScale',
  61. allowFullscreen : 'true',
  62. allowScriptAccess : 'always',
  63. wmode : 'transparent'
  64. };
  65. var attributes = {
  66. id : vars.id,
  67. name: vars.id
  68. };
  69. var swf = null;
  70. var callbackFn = function (e) {
  71. swf = e.ref;
  72. swf.eventHandler = function(json){
  73. callback.call(swf, json);
  74. };
  75. };
  76. swfobject.embedSWF(
  77. file,
  78. container,
  79. width,
  80. height,
  81. version,
  82. expressInstall,
  83. vars,
  84. params,
  85. attributes,
  86. callbackFn
  87. );
  88. return swf;
  89. }