flashVars.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. define("dojox/embed/flashVars", ['dojo'],function(dojo){
  2. dojo.getObject("dojox.embed", true);
  3. dojo.deprecated("dojox.embed.flashVars", "Will be removed in 2.0", "2.0");
  4. dojox.embed.flashVars = {
  5. // summary
  6. // Handles flashvar serialization
  7. // Converting complex objects into a simple, clear string that can be appended
  8. // to the swf as a query: myMovie.swf?flashvars=foo.
  9. // Note this needs to work with the SWF, which must know what variables to expect.
  10. // Therefore this is something of an "internal" class - unless you know how to
  11. // modify or create SWFs.
  12. //
  13. // description:
  14. // JSON could be done, but Deft does not yet have a JSON parser, and quotes are
  15. // very problematic since Flash cannot use eval(); JSON parsing was successful
  16. // when it was fully escaped, but that made it very large anyway. flashvar
  17. // serialization at most is 200% larger than JSON.
  18. //
  19. // See:
  20. // Deft/common/flashVars.as
  21. //
  22. serialize: function(/* String */n, /*Object*/o){
  23. // summary:
  24. // Key method. Serializes an object.
  25. // n:String
  26. // The name for the object, such as: "button"
  27. // o:Object
  28. // The object to serialize
  29. //
  30. var esc = function(val){
  31. // have to encode certain characters that indicate an object
  32. if(typeof val=="string"){
  33. val = val.replace(/;/g,"_sc_");
  34. val = val.replace(/\./g,"_pr_");
  35. val = val.replace(/\:/g,"_cl_");
  36. //val = escape(val);
  37. }
  38. return val;
  39. };
  40. var df = dojox.embed.flashVars.serialize;
  41. var txt = "";
  42. if(dojo.isArray(o)){
  43. for(var i=0;i<o.length;i++){
  44. txt += df(n+"."+i, esc(o[i]))+";";
  45. }
  46. return txt.replace(/;{2,}/g,";");
  47. }else if(dojo.isObject(o)){
  48. for(var nm in o){
  49. txt += df(n+"."+nm, esc(o[nm]))+";";
  50. }
  51. return txt.replace(/;{2,}/g,";");
  52. }
  53. // Dev note: important that there is no double semi-colons
  54. return n+":"+o; // String
  55. }
  56. };
  57. return dojox.embed.flashVars;
  58. });