| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 package { 2 import flash.external.ExternalInterface; 3 4 internal class ExternalCall 5 { 6 7 /*public function ExternalCall() 8 { 9 10 } 11 */ 12 13 public static function Simple(callback:String):void { 14 ExternalInterface.call(callback); 15 } 16 public static function FileQueued(callback:String, file_object:Object):void { 17 ExternalInterface.call(callback, EscapeMessage(file_object)); 18 } 19 public static function FileQueueError(callback:String, error_code:Number, file_object:Object, message:String):void { 20 21 ExternalInterface.call(callback, EscapeMessage(file_object), EscapeMessage(error_code), EscapeMessage(message)); 22 23 } 24 public static function FileDialogComplete(callback:String, num_files_selected:Number, num_files_queued:Number, total_num_files_queued:Number):void { 25 26 ExternalInterface.call(callback, EscapeMessage(num_files_selected), EscapeMessage(num_files_queued), EscapeMessage(total_num_files_queued)); 27 28 } 29 30 public static function UploadStart(callback:String, file_object:Object):void { 31 ExternalInterface.call(callback, EscapeMessage(file_object)); 32 } 33 34 public static function UploadProgress(callback:String, file_object:Object, bytes_loaded:uint, bytes_total:uint):void { 35 36 ExternalInterface.call(callback, EscapeMessage(file_object), EscapeMessage(bytes_loaded), EscapeMessage(bytes_total)); 37 38 } 39 public static function UploadSuccess(callback:String, file_object:Object, server_data:String, responseReceived:Boolean):void { 40 41 ExternalInterface.call(callback, EscapeMessage(file_object), EscapeMessage(server_data), EscapeMessage(responseReceived)); 42 43 } 44 public static function UploadError(callback:String, error_code:Number, file_object:Object, message:String):void { 45 46 ExternalInterface.call(callback, EscapeMessage(file_object), EscapeMessage(error_code), EscapeMessage(message)); 47 48 } 49 public static function UploadComplete(callback:String, file_object:Object):void { 50 51 ExternalInterface.call(callback, EscapeMessage(file_object)); 52 53 } 54 public static function Debug(callback:String, message:String):void { 55 56 ExternalInterface.call(callback, EscapeMessage(message)); 57 } 58 59 public static function Bool(callback:String):Boolean { 60 return ExternalInterface.call(callback); 61 } 62 63 64 /* Escapes all the backslashes which are not translated correctly in the Flash -> JavaScript Interface 65 * 66 * These functions had to be developed because the ExternalInterface has a bug that simply places the 67 * value a string in quotes (except for a " which is escaped) in a JavaScript string literal which 68 * is executed by the browser. These often results in improperly escaped string literals if your 69 * input string has any backslash characters. For example the string: 70 * "c:\Program Files\uploadtools\" 71 * is placed in a string literal (with quotes escaped) and becomes: 72 * var __flash__temp = "\"c:\Program Files\uploadtools\\""; 73 * This statement will cause errors when executed by the JavaScript interpreter: 74 * 1) The first \" is succesfully transformed to a " 75 * 2) \P is translated to P and the \ is lost 76 * 3) \u is interpreted as a unicode character and causes an error in IE 77 * 4) \\ is translated to \ 78 * 5) leaving an unescaped " which causes an error 79 * 80 * I fixed this by escaping \ characters in all outgoing strings. The above escaped string becomes: 81 * var __flash__temp = "\"c:\\Program Files\\uploadtools\\\""; 82 * which contains the correct string literal. 83 * 84 * Note: The "var __flash__temp = " portion of the example is part of the ExternalInterface not part of 85 * my escaping routine. 86 */ 87 private static function EscapeMessage(message:*):* { 88 if (message is String) { 89 message = EscapeString(message); 90 } 91 else if (message is Array) { 92 message = EscapeArray(message); 93 } 94 else if (message is Object) { 95 message = EscapeObject(message); 96 } 97 98 return message; 99 } 100 101 private static function EscapeString(message:String):String { 102 var replacePattern:RegExp = /\\/g; //new RegExp("/\\/", "g"); 103 return message.replace(replacePattern, "\\\\"); 104 } 105 private static function EscapeArray(message_array:Array):Array { 106 var length:uint = message_array.length; 107 var i:uint = 0; 108 for (i; i < length; i++) { 109 message_array[i] = EscapeMessage(message_array[i]); 110 } 111 return message_array; 112 } 113 private static function EscapeObject(message_obj:Object):Object { 114 for (var name:String in message_obj) { 115 message_obj[name] = EscapeMessage(message_obj[name]); 116 } 117 return message_obj; 118 } 119 120 } 121 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |