private InternalElement ConstructVendorLogo() { var element = new InternalElement { Name = "ManufacturerIcon", SupportedRoleClass = new SupportedRoleClass { RefRoleClassPath = "AutomationMLComponentStandardRCL/ManufacturerIcon" } }; var externalInterface = new ExternalInterface { Name = "ExternalDataConnector", RefBaseClassPath = "AutomationMLInterfaceClassLib/AutomationMLBaseInterface/ExternalDataConnector", Attribute = new Attribute { Name = "RefURI", AttributeDataType = "xs:anyURI", Value = new Value { Content = "/" + VendorLogo } } }; element.ExternalInterfaces.Add(externalInterface); return(element); }
public static void TryAddCallback(string functionName, Function closure) { /* * SecurityError: Error #2060: Security sandbox violation: ExternalInterface caller http://fc08.deviantart.net/fs70/f/2010/245/b/3/jsc_multitouch_teaser_by_zproxy-d2xu23s.swf cannot access http://sandbox.deviantart.com/?fileheight=480&filewidth=640&filename=fs70:f/2010/245/b/3/jsc_multitouch_teaser_by_zproxy-d2xu23s.swf. * at flash.external::ExternalInterface$/_initJS() * at flash.external::ExternalInterface$/addCallback() * at MultitouchFingerTools.FlashLAN::ApplicationSprite/__out_Method_100663299()[X:\web\MultitouchFingerTools\FlashLAN\ApplicationSprite.as:57] * at MultitouchFingerTools.FlashLAN::ApplicationSprite()[X:\web\MultitouchFingerTools\FlashLAN\ApplicationSprite.as:41] * * */ if (ExternalInterface.available) { try { ExternalInterface.addCallback(functionName, closure); } catch { // yay, should we report that? } } }
public static void Initialize(Action init_done) { if (InitializeDone) { init_done(); return; } InitializeDone = true; Diagnostics("Initialize..."); // does __Login exist? // add a callback ExternalInterface.call("setTimeout", "window.__check__Login = function (e) { return '__Login' in window; };", 0); Diagnostics("prepared __check__Login..."); 100.AtDelay( delegate { Diagnostics("call __check__Login..."); var value = (bool)ExternalInterface.call("__check__Login"); if (value) { // js app is ready for us! var y = default(HerokuFacebookLoginAppLoginExperienceAction); HerokuFacebookLoginAppLoginExperienceAction yield_to_sprite = (string id, string name, string third_party_id) => { if (y == null) { return; } y(id, name, third_party_id); y = null; }; ExternalExtensions.TryAddCallback("__Login_yield", yield_to_sprite.ToFunction()); __Login = yield => { y = yield; Diagnostics("context switch to js"); var value_Login = ExternalInterface.call("__Login"); }; init_done(); } else { Diagnostics("js app needs init"); } } ); }
public static void External <A0>(this string f, Action <A0> h) { ExternalInterface.addCallback(f, h.ToFunction()); }
public static void External <T, R>(this string f, Converter <T, R> h) { ExternalInterface.addCallback(f, h.ToFunction()); }
public static object External(this string f, object a0, object a1, object a2, object a3, object a4, object a5) { return(ExternalInterface.call(f, a0, a1, a2, a3, a4, a5)); }
public static object External(this string f, object a0, object a1, object a2) { return(ExternalInterface.call(f, a0, a1, a2)); }
public static object External(this string f) { return(ExternalInterface.call(f)); }
public static void Initialize(Action <string> yield_to_sprite) { #region export callback ExternalExtensions.TryAddCallback("WhenReady", yield_to_sprite.ToFunction()); #endregion #region Initialize JavaScript //TypeError: Cannot call method 'apply' of undefined //ExternalInterface.call("setTimeout", "window.function2 = function (e) { document.title = 'length: ' + e.length; document.getElementById('foo').value = e; return 0; };", 0); ExternalInterface.call("setTimeout", @"window.function2 = function (e) { console.log('length: ' + e.length); // debugger; var f = null; //try //{ f = eval(e); console.log('done!'); //} //catch (err) //{ // console.log('error! ' + err); // console.log('typeof f: ' + typeof f); // console.log('f: ' + f); //} return 0; };", 0); //ExternalInterface.call("setTimeout", "window.function1 = function (e) { alert(e.length); };", 0); //ExternalInterface.call("setTimeout", "document.title = 'flashed';", 0); var source = KnownEmbeddedResources.Default["assets/FlashBootstrapsSecondaryApplication/view-source"].ToStringAsset(); //content.t.Text = new { source.Length }.ToString(); //ExternalInterface.call("setTimeout", "document.title = 'source';", 0); //ExternalInterface.call("function2", "hi").ToString(); //ExternalInterface.call("function2", "<\\&>\n\r\t<A//>").ToString(); 1.AtDelay( delegate { // Uncaught SyntaxError: Unexpected token ILLEGAL //var x = 1024 * 31 + 1; //var x = 1024 * 30 + 1 + 256; //var x = 1024 * 30 + 1 + 256 + 64 + 48 + 5; //for (d = 0; (d < AQQABtNdQz66ZYUODttTfw(c)); d++) //{ // e = EwQABtNdQz66ZYUODttTfw(c, d); // f = CQQABtNdQz66ZYUODttTfw(c, d); // i = !(EAQABtNdQz66ZYUODttTfw('\"\'\u005c\u0008\u000c\u000a\u000d\u0009', e) > -1); // YUODttTfw('\""\ } // tTfw('\""\u005c } var q = source; //.Substring(x, 16); //q = q.Replace("\\'", "X"); //q = q.Replace("\\\"", "\\x22"); q = q.Replace("\\", "\\\\"); //q = q.Replace("'", "X"); // { x = 31041, Length = 1118850, q = 66ZYUODttTfw(c, d); //i = !(EAQABtNdQz66Z } // { x = 31089, Length = 1118850, q = YUODttTfw('\"\'\ } //content.t.Text = new { x, source.Length, q }.ToString(); try { ExternalInterface.call("function2", q); } catch (Exception ex) { //content.t.Text = "error? " + new { ex.Message, ex.StackTrace }; } } ); //ExternalInterface.call("function1", // // too much // //"hello world".PadLeft(1024 * 1024) // // too much // //"hello world".PadLeft(1024 * 512) // // 8K OK // //"hello world".PadLeft(1024 * 8) // // 131072 OK // //"hello world".PadLeft(1024 * 8 * 16) // // something wrong with pad? // //524288 // // 1048576 // // 4194304 // 1118850 // //new string('x', 1024 * 1024 * 4) // source // ).ToString(); #endregion }
// http://curtismorley.com/2008/11/01/actionscript-security-error-2060-security-sandbox-violation/ // http://blog.deconcept.com/code/externalinterface.html // http://blog.warptube.com/2008/12/2/oddities-with-externalinterface-and-ie public ApplicationSprite() { addChild( new TextField { text = ExternalInterface.available ? "ExternalInterface available" : "ExternalInterface not available", x = 20, y = 20, selectable = false, textColor = 0xffffff, autoSize = TextFieldAutoSize.LEFT, mouseEnabled = false } ); addChild( new TextField { text = Security.sandboxType, x = 20, y = 40, selectable = false, textColor = 0xffffff, autoSize = TextFieldAutoSize.LEFT, mouseEnabled = false } ); Security.allowDomain("*"); var status = new TextField { text = "ready", x = 20, y = 80, selectable = false, textColor = 0xffffff, autoSize = TextFieldAutoSize.LEFT, mouseEnabled = false }.AttachTo(this); Func <string, Sprite> CreateButton = text => { var z = new Sprite(); z.graphics.beginFill(0xff0000); z.graphics.drawRect(0, 0, 100, 20); z.graphics.endFill(); z.width = 100; z.height = 20; new TextField { text = text, mouseEnabled = false, width = 100, height = 20 }.AttachTo(z); return(z); }; Func <string, Action, Sprite> AddButton = (text, click) => { var z = CreateButton(text); z.click += delegate { click(); }; z.AttachTo(this); return(z); }; var s = AddButton("call function1!", delegate { status.text = "click!"; try { ExternalInterface.call("setTimeout", "document.title = 'flashed';", 0); status.text = ExternalInterface.call("function1", "hello world").ToString(); } catch (Exception ex) { status.text = ex.Message; } } ); var a = AddButton("show settings!", delegate { status.text = "settings!"; Security.showSettings(); } ); a.x = 102; var b = AddButton("add callback!", delegate { status.text = "new callback!"; Action function2 = delegate { status.text = "function2 called"; }; ExternalInterface.addCallback("function2", function2.ToFunction()); } ); b.x = 204; //ExternalInterface.call("setTimeout", "document.title = 'ready';", 0); }