public ApplicationSprite() { #region __transport for (int i = 0; i < 7; i++) { lag.Enqueue(new List <string>()); } var lagtimer = new ScriptCoreLib.ActionScript.flash.utils.Timer(1000 / 15); lagtimer.timer += delegate { lag.Enqueue(PendingInput); PendingInput = lag.Dequeue(); foreach (var xml in PendingInput) { this.__transport_in(xml); } PendingInput.Clear(); }; lagtimer.start(); StarlingGameSpriteWithTankSync.__raise_sync += egoid => { // Error 8 Argument 1: cannot convert from 'System.Xml.Linq.XAttribute' to 'System.Xml.Linq.XStreamingElement' X:\jsc.svn\examples\actionscript\svg\FlashHeatZeeker\FlashHeatZeeker.UnitPedSync\ApplicationSprite.cs 40 33 FlashHeatZeeker.UnitPedSync var xml = new XElement("sync", new XAttribute("egoid", egoid)); if (__transport_out != null) { __transport_out(xml.ToString()); } }; StarlingGameSpriteWithTankSync.__raise_SetVelocityFromInput += ( string __egoid, string __identity, string __KeySample, string __fixup_x, string __fixup_y, string __fixup_angle ) => { var xml = new XElement("SetVelocityFromInput", new XAttribute("egoid", __egoid), new XAttribute("i", __identity), new XAttribute("k", __KeySample), new XAttribute("x", __fixup_x), new XAttribute("y", __fixup_y), new XAttribute("angle", __fixup_angle) ); if (__transport_out != null) { __transport_out(xml.ToString()); } }; #endregion this.InvokeWhenStageIsReady( delegate { // http://gamua.com/starling/first-steps/ // http://forum.starling-framework.org/topic/starling-air-desktop-extendeddesktop-fullscreen-issue Starling.handleLostContext = true; var s = new Starling( typeof(StarlingGameSpriteWithTankSync).ToClassToken(), this.stage ); //Starling.current.showStats s.showStats = true; // when can we have live constant updates? new net.hires.debug.Stats().AttachToSprite().MoveTo(0, 48); #region atresize Action atresize = delegate { // http://forum.starling-framework.org/topic/starling-stage-resizing s.viewPort = new ScriptCoreLib.ActionScript.flash.geom.Rectangle( 0, 0, this.stage.stageWidth, this.stage.stageHeight ); s.stage.stageWidth = this.stage.stageWidth; s.stage.stageHeight = this.stage.stageHeight; //b2stage_centerize(); }; atresize(); #endregion StarlingGameSpriteBase.onresize = yield => { this.stage.resize += delegate { atresize(); yield(this.stage.stageWidth, this.stage.stageHeight); }; yield(this.stage.stageWidth, this.stage.stageHeight); }; this.stage.enterFrame += delegate { StarlingGameSpriteBase.onframe(this.stage, s); }; s.start(); } ); }
public ExternalContext() { if (ExternalContextCreated) { throw new Exception("ExternalContextCreated"); } ExternalContextCreated = true; var r = new Random(); a = "_" + r.Next(0x7ffffff); b = "_" + r.Next(0x7ffffff); #region ExternalAuthentication var Handler = default(Converter <string, string>); Handler = value => { if (value == a) { Handler = id => { if (InternalId != null) { throw new Exception("already has id"); } InternalId = id; InternalElement = new IHTMLObject { id = id }; InternalElement.Token.Context = this; Handler = e => ""; var t = new ScriptCoreLib.ActionScript.flash.utils.Timer(1, 1); t.timerComplete += delegate { if (ElementChanged != null) { ElementChanged(); } }; t.start(); return(""); }; return(b); } return(value); }; a.External( (string e) => Handler(e) ); #endregion this.SetElementPropertyString = ToExternal <string, string, string>( "_id", "_key", "_value", "document.getElementById(_id)[_key] = _value;" ); this.GetGlobalPropertyString = ToExternalConverter <string, string, string>( "_id", "_key", "return window[_id][_key];" ); this.SetGlobalPropertyString = ToExternal <string, string, string>( "_id", "_key", "_value", "window[_id][_key] = _value;" ); this.ExternalContext_IHTMLDocument_createElement = ToExternal <string, string>( "_tag", "_i", "window[_i] = document.createElement(_tag);" ); this.ExternalContext_IHTMLDocument_get_body = ToExternal <string>( "_i", "window[_i] = document.body;" ); this.ExternalContext_IHTMLElement_set_innerHTML = ToExternal <string, string>( "_value", "_i", "window[_i].innerHTML = _value;" ); this.ExternalContext_IHTMLElement_appendChild = ToExternal <string, string>( "_parent", "_child", "window[_parent].appendChild(window[_child]);" ); this.ExternalContext_getElementById_call_string = ToExternal <string, string, string>( "_i", "_f", "_a0", "document.getElementById(_i)[_f](_a0);" ); this.ExternalContext_getElementById_call_string_string = ToExternal <string, string, string, string>( "_i", "_f", "_a0", "_a1", "document.getElementById(_i)[_f](_a0, _a1);" ); this.ExternalContext_getElementById_call_string_string_string = ToExternal <string, string, string, string, string>( "_i", "_f", "_a0", "_a1", "_a2", "document.getElementById(_i)[_f](_a0, _a1, _a2);" ); this.ExternalContext_token_call_string = ToExternal <string, string, string>( "_i", "_f", "_a0", "window[_i][_f](_a0);" ); this.ExternalContext_token_call_token = ToExternal <string, string, string>( "_i", "_f", "_j", "window[_i][_f](window[_j]);" ); this.ExternalContext_token_call_string_string_string = ToExternal <string, string, string, string, string>( "_i", "_f", "_a0", "_a1", "_a2", "window[_i][_f](_a0, _a1, _a2);" ); this.ExternalContext_token_set_property = ToExternal <string, string, object>( "_i", "_f", "_v", "window[_i][_f] = _v;" ); this.ExternalContext_getElementById_call = ToExternal <string, string>( "_i", "_f", "document.getElementById(_i)[_f]();" ); this.ExternalContext_token_call = ToExternal <string, string>( "_i", "_f", "window[_i][_f]();" ); this.ExternalContext_token_set_getElementById = ToExternal <string, string>( "_r", "_i", "window[_r] = document.getElementById(_i);" ); this.ExternalContext_let_token_get_property = ToExternal <string, string, string>( "_r", "_i", "_p", "window[_r] = window[_i][_p];" ); #region add_event // http://mihai.bazon.net/blog/flash-s-externalinterface-and-ie // http://swfupload.org/forum/generaldiscussion/985 // ie is unable to load flash external interface if the object was created by innerHTML this.ExternalContext_getElementById_add_event = ToExternal <string, string, string, string>( "_i", "_f", "_j", "_h", // attachEvent = on // @" // var _element = document.getElementById(_i); // if ('attachEvent' in _element) alert('ie event'); // else if ('addEventListener' in _element) alert('ff event'); // " @" var _element = document.getElementById(_i); if ('addEventListener' in _element) { _element.addEventListener(_f, function () { document.getElementById(_j)[_h](); }, false ); } " ); this.ExternalContext_token_add_event = ToExternal <string, string, string, string>( "_i", "_f", "_j", "_h", // attachEvent = on // @" // var _element = document.getElementById(_i); // if ('attachEvent' in _element) alert('ie event'); // else if ('addEventListener' in _element) alert('ff event'); // " @" var _element = window[_i]; if ('addEventListener' in _element) { _element.addEventListener(_f, function () { document.getElementById(_j)[_h](); }, false ); } " ); #endregion }
public ApplicationSprite() { #region __transport for (int i = 0; i < 7; i++) { lag.Enqueue(new List<string>()); } var lagtimer = new ScriptCoreLib.ActionScript.flash.utils.Timer(1000 / 15); lagtimer.timer += delegate { lag.Enqueue(PendingInput); PendingInput = lag.Dequeue(); foreach (var xml in PendingInput) { this.__transport_in(xml); } PendingInput.Clear(); }; lagtimer.start(); StarlingGameSpriteWithTankSync.__raise_sync += egoid => { // Error 8 Argument 1: cannot convert from 'System.Xml.Linq.XAttribute' to 'System.Xml.Linq.XStreamingElement' X:\jsc.svn\examples\actionscript\svg\FlashHeatZeeker\FlashHeatZeeker.UnitPedSync\ApplicationSprite.cs 40 33 FlashHeatZeeker.UnitPedSync var xml = new XElement("sync", new XAttribute("egoid", egoid)); if (__transport_out != null) __transport_out(xml.ToString()); }; StarlingGameSpriteWithTankSync.__raise_SetVelocityFromInput += ( string __egoid, string __identity, string __KeySample, string __fixup_x, string __fixup_y, string __fixup_angle ) => { var xml = new XElement("SetVelocityFromInput", new XAttribute("egoid", __egoid), new XAttribute("i", __identity), new XAttribute("k", __KeySample), new XAttribute("x", __fixup_x), new XAttribute("y", __fixup_y), new XAttribute("angle", __fixup_angle) ); if (__transport_out != null) __transport_out(xml.ToString()); }; #endregion this.InvokeWhenStageIsReady( delegate { // http://gamua.com/starling/first-steps/ // http://forum.starling-framework.org/topic/starling-air-desktop-extendeddesktop-fullscreen-issue Starling.handleLostContext = true; var s = new Starling( typeof(StarlingGameSpriteWithTankSync).ToClassToken(), this.stage ); //Starling.current.showStats s.showStats = true; // when can we have live constant updates? new net.hires.debug.Stats().AttachToSprite().MoveTo(0, 48); #region atresize Action atresize = delegate { // http://forum.starling-framework.org/topic/starling-stage-resizing s.viewPort = new ScriptCoreLib.ActionScript.flash.geom.Rectangle( 0, 0, this.stage.stageWidth, this.stage.stageHeight ); s.stage.stageWidth = this.stage.stageWidth; s.stage.stageHeight = this.stage.stageHeight; //b2stage_centerize(); }; atresize(); #endregion StarlingGameSpriteBase.onresize = yield => { this.stage.resize += delegate { atresize(); yield(this.stage.stageWidth, this.stage.stageHeight); }; yield(this.stage.stageWidth, this.stage.stageHeight); }; this.stage.enterFrame += delegate { StarlingGameSpriteBase.onframe(this.stage, s); }; s.start(); } ); }
public static void InvokeWhenPromotionIsReady <T>(this T context, Action yield = null) where T : DisplayObjectContainer, IAlternator { var sb = new Soundboard(); sb.loopheartbeat3.LeftVolume = 0.1; sb.loopheartbeat3.RightVolume = 0.1; var heart = sb.loopheartbeat3.Sound.play(); context.InvokeWhenStageIsReady( delegate { Bitmap i = null; if (context.Alternate == "green") { sb.snd_nightvision.play(); i = new ActionScript.Images.Promotion3D_iso1_tiltshift_720p_green(); } else { sb.snd_SelectWeapon.play(); i = new ActionScript.Images.Promotion3D_iso1_tiltshift_720p(); } i.AttachTo(context); i.x = (i.stage.stageWidth - 1280) / 2; i.y = (i.stage.stageHeight - 720) / 2; context.stage.resize += delegate { if (i == null) { return; } i.x = (i.stage.stageWidth - 1280) / 2; i.y = (i.stage.stageHeight - 720) / 2; }; { var tt = new ScriptCoreLib.ActionScript.flash.utils.Timer(1000 / 15); tt.timer += delegate { if (i.alpha > 0.07) { i.alpha -= 0.07; } else { i.Orphanize(); i = null; if (yield != null) { yield(); } tt.stop(); } }; var t = new ScriptCoreLib.ActionScript.flash.utils.Timer(4000, 1); t.timerComplete += delegate { tt.start(); }; t.start(); } #region heart.stop { var tt = new ScriptCoreLib.ActionScript.flash.utils.Timer(1000 / 5); tt.timer += delegate { if (sb.loopheartbeat3.MasterVolume > 0.07) { sb.loopheartbeat3.MasterVolume -= 0.07; } else { heart.stop(); tt.stop(); } }; var t = new ScriptCoreLib.ActionScript.flash.utils.Timer(1500, 1); t.timerComplete += delegate { sb.snd_letsgo.play(); tt.start(); }; t.start(); } #endregion } ); }
public ApplicationSprite() { #region __transport for (int i = 0; i < 7; i++) { lag.Enqueue(new List<string>()); } var lagtimer = new ScriptCoreLib.ActionScript.flash.utils.Timer(1000 / 15); lagtimer.timer += delegate { lag.Enqueue(PendingInput); PendingInput = lag.Dequeue(); foreach (var xml in PendingInput) { this.__transport_in(xml); } PendingInput.Clear(); }; lagtimer.start(); StarlingGameSpriteWithPedSync.__raise_sync += egoid => { // Error 8 Argument 1: cannot convert from 'System.Xml.Linq.XAttribute' to 'System.Xml.Linq.XStreamingElement' X:\jsc.svn\examples\actionscript\svg\FlashHeatZeeker\FlashHeatZeeker.UnitPedSync\ApplicationSprite.cs 40 33 FlashHeatZeeker.UnitPedSync var xml = new XElement("sync", new XAttribute("egoid", egoid)); if (__transport_out != null) __transport_out(xml.ToString()); }; StarlingGameSpriteWithPedSync.__raise_SetVelocityFromInput += ( string __egoid, string __identity, string __KeySample, string __fixup_x, string __fixup_y, string __fixup_angle ) => { var xml = new XElement("SetVelocityFromInput", new XAttribute("egoid", __egoid), new XAttribute("i", __identity), new XAttribute("k", __KeySample), new XAttribute("x", __fixup_x), new XAttribute("y", __fixup_y), new XAttribute("angle", __fixup_angle) ); if (__transport_out != null) __transport_out(xml.ToString()); }; #endregion #region AtInitializeConsoleFormWriter var w = new __OutWriter(); var o = Console.Out; var __reentry = false; var __buffer = new StringBuilder(); w.AtWrite = x => { __buffer.Append(x); }; w.AtWriteLine = x => { __buffer.AppendLine(x); }; Console.SetOut(w); this.AtInitializeConsoleFormWriter = ( Action<string> Console_Write, Action<string> Console_WriteLine ) => { try { w.AtWrite = x => { o.Write(x); if (!__reentry) { __reentry = true; Console_Write(x); __reentry = false; } }; w.AtWriteLine = x => { o.WriteLine(x); if (!__reentry) { __reentry = true; Console_WriteLine(x); __reentry = false; } }; Console.WriteLine("flash Console.WriteLine should now appear in JavaScript form!"); Console.WriteLine(__buffer.ToString()); } catch { } }; #endregion this.InvokeWhenStageIsReady( delegate { // http://gamua.com/starling/first-steps/ // http://forum.starling-framework.org/topic/starling-air-desktop-extendeddesktop-fullscreen-issue Starling.handleLostContext = true; var s = new Starling( typeof(StarlingGameSpriteWithPedSync).ToClassToken(), this.stage ); //Starling.current.showStats s.showStats = true; #region atresize Action atresize = delegate { // http://forum.starling-framework.org/topic/starling-stage-resizing s.viewPort = new ScriptCoreLib.ActionScript.flash.geom.Rectangle( 0, 0, this.stage.stageWidth, this.stage.stageHeight ); s.stage.stageWidth = this.stage.stageWidth; s.stage.stageHeight = this.stage.stageHeight; //b2stage_centerize(); }; atresize(); #endregion StarlingGameSpriteBase.onresize = yield => { this.stage.resize += delegate { atresize(); yield(this.stage.stageWidth, this.stage.stageHeight); }; yield(this.stage.stageWidth, this.stage.stageHeight); }; this.stage.enterFrame += delegate { StarlingGameSpriteBase.onframe(this.stage, s); }; s.start(); } ); }
// http://www.onflex.org/flexapps/components/CustomPreloader/srcview/index.html // http://www.onflex.org/ted/2006/07/flex-2-custom-preloaders.php // http://www.onflex.org/flexapps/components/CustomPreloader/PNG/srcview/ // http://www.flexer.info/2008/02/07/very-first-flex-preloader-customization/ // http://www.nulldesign.de/2007/11/30/as3-preloading-continued/ // http://adventuresinactionscript.com/blog/03-04-2008/as3-preloader-with-mochiad-mochibot-simple-domain-locking-and-glossy-vista-style-pro // http://blog.jerrydon.com/index.php/2008/07/fullscreen-flex-preloader/ // http://www.docsultant.com/site2/articles/flex_cmd.html // http://jerrydon.com/flex/fullscreenpreloader/srcview/index.html // http://www.ghost23.de/blogarchive/2008/04/as3-application-1.html // http://livedocs.adobe.com/flex/3/langref/mx/preloaders/DownloadProgressBar.html // http://livedocs.adobe.com/flex/3/html/help.html?content=app_container_4.html // http://www.bit-101.com/blog/?p=946 public ApplicationSpritePreloader() { this.stage.align = StageAlign.TOP_LEFT; this.stage.scaleMode = StageScaleMode.NO_SCALE; if (((int)new Date().seconds % 2) == 0) { Alternate = "green"; } var scale = 720.0 / 225.0; // this.stage.color Bitmap i = new ActionScript.Images.Promotion3D_iso1_tiltshift_400x225(); if (Alternate == "green") { i = new ActionScript.Images.Promotion3D_iso1_tiltshift_400x225_green(); this.stage.color = 0x006A00; } else { this.stage.color = 0x9A6C46; } i.AttachTo(this); i.scaleX = scale; i.scaleY = scale; i.x = (i.stage.stageWidth - 1280) / 2; i.y = (i.stage.stageHeight - 720) / 2; this.stage.resize += delegate { if (i == null) { return; } i.x = (i.stage.stageWidth - 1280) / 2; i.y = (i.stage.stageHeight - 720) / 2; }; var te = new TextField { textColor = 0xffffff, autoSize = TextFieldAutoSize.LEFT, //width = 800, }.AttachTo(this).MoveTo(8, 8); // http://stackoverflow.com/questions/859526/flash-progressevent-not-showing-total-size // http://stackoverflow.com/questions/8234862/what-to-do-when-loaderinfo-bytestotal-is-zero // http://stackoverflow.com/questions/1269875/why-loaderinfo-bytestotal-is-zero/14964646#14964646 this.LoadingInProgress += delegate { var per = (int)Math.Floor(100.0 * root.loaderInfo.bytesLoaded / root.loaderInfo.bytesTotal); te.text = "... " + loaderInfo.bytesLoaded; //te.text = "LoadingInProgress " + new { root.loaderInfo.bytesLoaded, root.loaderInfo.bytesTotal /*, framesLoaded, totalFrames */}.ToString(); //te.text = per + "%"; }; this.LoadingComplete += delegate { //te.text = "LoadingComplete... " + new { root.loaderInfo.bytesLoaded, root.loaderInfo.bytesTotal /*, framesLoaded, totalFrames */}.ToString(); try { var x = CreateInstance(); //te.text = "LoadingComplete " + new { root.loaderInfo.bytesLoaded, root.loaderInfo.bytesTotal /*, framesLoaded, totalFrames */, x }.ToString(); var a = x as IAlternator; a.Alternate = Alternate; var t = new ScriptCoreLib.ActionScript.flash.utils.Timer(700, 1); t.timerComplete += delegate { //te.text = "LoadingComplete timerComplete " + new { root.loaderInfo.bytesLoaded, root.loaderInfo.bytesTotal /*, framesLoaded, totalFrames */, x }.ToString(); x.AttachTo(this); i.Orphanize(); i = null; te.Orphanize(); }; t.start(); } catch (Exception ex) { te.text = ("error: " + new { ex } +"\n run in flash debugger for more details!"); } }; }
public static void InitializeConnection( this KeySample key, bool WriteMode = true, bool ReadMode = false, TextField text = null, Action<Action<string>> yield_PostMessage = null, Action<XElement> yield_Notify = null ) { //var that = new { About }; var nc = new NetConnection(); var connected = false; Action<string> RaiseMessage = x => { if (text != null) { //text.text = x + Environment.NewLine + text.text; text.text = x; } }; Action<string> PostMessage = message => { RaiseMessage("drop: " + message); }; if (WriteMode) { var sync = new ScriptCoreLib.ActionScript.flash.utils.Timer(1000 / 60); var syncid = 0; var was = -1; sync.timer += delegate { if (key.value == was) if (was == 0) return; syncid++; PostMessage( new XElement("sync", new XElement("KeySample", new XAttribute("value", "" + key.value), new XAttribute("forcex", "" + key.forcex), new XAttribute("forcey", "" + key.forcey), new XAttribute("syncid", "" + syncid) ) ).ToString() ); was = key.value; }; sync.start(); } //that.AtNotifyVisualizeTouch += // (x, y) => // { // XElement VisualizeTouch = new DoubleVector2 // { // X = x, // Y = y // }; // PostMessage( // new XElement("Updates", // new XElement("VisualizeTouch", VisualizeTouch) // ).ToString() // ); // }; nc.netStatus += e => { RaiseMessage("nc.netStatus: " + e.info.code); if (e.info.code == "NetGroup.Connect.Success") { connected = true; RaiseMessage("connected, looking for long range coms... (7 to 30sec delay) might need to reset android wifi, pc wifi or wifi router itself!"); return; } if (e.info.code == "NetConnection.Connect.Success") { RaiseMessage("looking for long range coms... looking for permission..."); var groupspec = new GroupSpecifier("myGroup/groupOne"); groupspec.postingEnabled = true; groupspec.ipMulticastMemberUpdatesEnabled = true; groupspec.addIPMulticastAddress("225.225.0.1:30303"); var group = new NetGroup(nc, groupspec.groupspecWithAuthorizations()); PostMessage = message => { if (connected) { RaiseMessage("write: " + message); group.post(message); } else { RaiseMessage("skip: " + message); } }; if (yield_PostMessage != null) yield_PostMessage(PostMessage); //if (WriteMode) //{ // PostMessage( // new XElement("KeySample", // new XAttribute("value", "" + key.value) // ).ToString() // ); //} //AtPostMessage += PostMessage; group.netStatus += g => { if (g.info.code == "NetGroup.Posting.Notify") { // Type Coercion failed: cannot convert Object@60b6cb9 to LANMulticast_Components_MySprite1__f__AnonymousType0_1_33554444. var source = (string)g.info.message; //Console.WriteLine("source: " + source); RaiseMessage("source: " + source); var xml = XElement.Parse(source); //xml.Elements().Where(k => k.Name.LocalName == "BuildRocket").Elements().WithEach( // ksource => // { // //Console.WriteLine("BuildRocket: " + ksource); // DoubleVector2 k = ksource; // that.NotifyBuildRocket(k.X, k.Y); // } //); if (yield_Notify != null) { yield_Notify(xml); } if (ReadMode) { //xml.Elements().Where(k => k.Name.LocalName == "KeySample").WithEach( xml.Elements("KeySample").WithEach( ksource => { var value = int.Parse(ksource.Attribute("value").Value); var forcex = double.Parse(ksource.Attribute("forcex").Value); var forcey = double.Parse(ksource.Attribute("forcey").Value); //RaiseMessage("value: " + value); key.value = value; key.forcex = forcex; key.forcey = forcey; //Console.WriteLine("VisualizeTouch: " + ksource); //new XElement("value", "" + k.value) //DoubleVector2 k = ksource; //that.NotifyVisualizeTouch(k.X, k.Y); } ); } return; } RaiseMessage("group.netStatus: " + g.info.code); }; return; } }; nc.connect("rtmfp:"); }
public ApplicationSprite() { #region __transport for (int i = 0; i < 7; i++) { lag.Enqueue(new List <string>()); } var lagtimer = new ScriptCoreLib.ActionScript.flash.utils.Timer(1000 / 15); lagtimer.timer += delegate { lag.Enqueue(PendingInput); PendingInput = lag.Dequeue(); foreach (var xml in PendingInput) { this.__transport_in(xml); } PendingInput.Clear(); }; lagtimer.start(); StarlingGameSpriteWithPedSync.__raise_sync += egoid => { // Error 8 Argument 1: cannot convert from 'System.Xml.Linq.XAttribute' to 'System.Xml.Linq.XStreamingElement' X:\jsc.svn\examples\actionscript\svg\FlashHeatZeeker\FlashHeatZeeker.UnitPedSync\ApplicationSprite.cs 40 33 FlashHeatZeeker.UnitPedSync var xml = new XElement("sync", new XAttribute("egoid", egoid)); if (__transport_out != null) { __transport_out(xml.ToString()); } }; StarlingGameSpriteWithPedSync.__raise_SetVelocityFromInput += ( string __egoid, string __identity, string __KeySample, string __fixup_x, string __fixup_y, string __fixup_angle ) => { var xml = new XElement("SetVelocityFromInput", new XAttribute("egoid", __egoid), new XAttribute("i", __identity), new XAttribute("k", __KeySample), new XAttribute("x", __fixup_x), new XAttribute("y", __fixup_y), new XAttribute("angle", __fixup_angle) ); if (__transport_out != null) { __transport_out(xml.ToString()); } }; #endregion #region AtInitializeConsoleFormWriter var w = new __OutWriter(); var o = Console.Out; var __reentry = false; var __buffer = new StringBuilder(); w.AtWrite = x => { __buffer.Append(x); }; w.AtWriteLine = x => { __buffer.AppendLine(x); }; Console.SetOut(w); this.AtInitializeConsoleFormWriter = ( Action <string> Console_Write, Action <string> Console_WriteLine ) => { try { w.AtWrite = x => { o.Write(x); if (!__reentry) { __reentry = true; Console_Write(x); __reentry = false; } }; w.AtWriteLine = x => { o.WriteLine(x); if (!__reentry) { __reentry = true; Console_WriteLine(x); __reentry = false; } }; Console.WriteLine("flash Console.WriteLine should now appear in JavaScript form!"); Console.WriteLine(__buffer.ToString()); } catch { } }; #endregion this.InvokeWhenStageIsReady( delegate { // http://gamua.com/starling/first-steps/ // http://forum.starling-framework.org/topic/starling-air-desktop-extendeddesktop-fullscreen-issue Starling.handleLostContext = true; var s = new Starling( typeof(StarlingGameSpriteWithPedSync).ToClassToken(), this.stage ); //Starling.current.showStats s.showStats = true; #region atresize Action atresize = delegate { // http://forum.starling-framework.org/topic/starling-stage-resizing s.viewPort = new ScriptCoreLib.ActionScript.flash.geom.Rectangle( 0, 0, this.stage.stageWidth, this.stage.stageHeight ); s.stage.stageWidth = this.stage.stageWidth; s.stage.stageHeight = this.stage.stageHeight; //b2stage_centerize(); }; atresize(); #endregion StarlingGameSpriteBase.onresize = yield => { this.stage.resize += delegate { atresize(); yield(this.stage.stageWidth, this.stage.stageHeight); }; yield(this.stage.stageWidth, this.stage.stageHeight); }; this.stage.enterFrame += delegate { StarlingGameSpriteBase.onframe(this.stage, s); }; s.start(); } ); }
public static void InitializeConnection( this KeySample key, bool WriteMode = true, bool ReadMode = false, TextField text = null, Action <Action <string> > yield_PostMessage = null, Action <XElement> yield_Notify = null ) { //var that = new { About }; var nc = new NetConnection(); var connected = false; Action <string> RaiseMessage = x => { if (text != null) { //text.text = x + Environment.NewLine + text.text; text.text = x; } }; Action <string> PostMessage = message => { RaiseMessage("drop: " + message); }; if (WriteMode) { var sync = new ScriptCoreLib.ActionScript.flash.utils.Timer(1000 / 60); var syncid = 0; var was = -1; sync.timer += delegate { if (key.value == was) { if (was == 0) { return; } } syncid++; PostMessage( new XElement("sync", new XElement("KeySample", new XAttribute("value", "" + key.value), new XAttribute("forcex", "" + key.forcex), new XAttribute("forcey", "" + key.forcey), new XAttribute("syncid", "" + syncid) ) ).ToString() ); was = key.value; }; sync.start(); } //that.AtNotifyVisualizeTouch += // (x, y) => // { // XElement VisualizeTouch = new DoubleVector2 // { // X = x, // Y = y // }; // PostMessage( // new XElement("Updates", // new XElement("VisualizeTouch", VisualizeTouch) // ).ToString() // ); // }; nc.netStatus += e => { RaiseMessage("nc.netStatus: " + e.info.code); if (e.info.code == "NetGroup.Connect.Success") { connected = true; RaiseMessage("connected, looking for long range coms... (7 to 30sec delay) might need to reset android wifi, pc wifi or wifi router itself!"); return; } if (e.info.code == "NetConnection.Connect.Success") { RaiseMessage("looking for long range coms... looking for permission..."); var groupspec = new GroupSpecifier("myGroup/groupOne"); groupspec.postingEnabled = true; groupspec.ipMulticastMemberUpdatesEnabled = true; groupspec.addIPMulticastAddress("225.225.0.1:30303"); var group = new NetGroup(nc, groupspec.groupspecWithAuthorizations()); PostMessage = message => { if (connected) { RaiseMessage("write: " + message); group.post(message); } else { RaiseMessage("skip: " + message); } }; if (yield_PostMessage != null) { yield_PostMessage(PostMessage); } //if (WriteMode) //{ // PostMessage( // new XElement("KeySample", // new XAttribute("value", "" + key.value) // ).ToString() // ); //} //AtPostMessage += PostMessage; group.netStatus += g => { if (g.info.code == "NetGroup.Posting.Notify") { // Type Coercion failed: cannot convert Object@60b6cb9 to LANMulticast_Components_MySprite1__f__AnonymousType0_1_33554444. var source = (string)g.info.message; //Console.WriteLine("source: " + source); RaiseMessage("source: " + source); var xml = XElement.Parse(source); //xml.Elements().Where(k => k.Name.LocalName == "BuildRocket").Elements().WithEach( // ksource => // { // //Console.WriteLine("BuildRocket: " + ksource); // DoubleVector2 k = ksource; // that.NotifyBuildRocket(k.X, k.Y); // } //); if (yield_Notify != null) { yield_Notify(xml); } if (ReadMode) { //xml.Elements().Where(k => k.Name.LocalName == "KeySample").WithEach( xml.Elements("KeySample").WithEach( ksource => { var value = int.Parse(ksource.Attribute("value").Value); var forcex = double.Parse(ksource.Attribute("forcex").Value); var forcey = double.Parse(ksource.Attribute("forcey").Value); //RaiseMessage("value: " + value); key.value = value; key.forcex = forcex; key.forcey = forcey; //Console.WriteLine("VisualizeTouch: " + ksource); //new XElement("value", "" + k.value) //DoubleVector2 k = ksource; //that.NotifyVisualizeTouch(k.X, k.Y); } ); } return; } RaiseMessage("group.netStatus: " + g.info.code); }; return; } }; nc.connect("rtmfp:"); }
public ExternalContext() { if (ExternalContextCreated) throw new Exception("ExternalContextCreated"); ExternalContextCreated = true; var r = new Random(); a = "_" + r.Next(0x7ffffff); b = "_" + r.Next(0x7ffffff); #region ExternalAuthentication var Handler = default(Converter<string, string>); Handler = value => { if (value == a) { Handler = id => { if (InternalId != null) throw new Exception("already has id"); InternalId = id; InternalElement = new IHTMLObject { id = id }; InternalElement.Token.Context = this; Handler = e => ""; var t = new ScriptCoreLib.ActionScript.flash.utils.Timer(1, 1); t.timerComplete += delegate { if (ElementChanged != null) ElementChanged(); }; t.start(); return ""; }; return b; } return value; }; a.External( (string e) => Handler(e) ); #endregion this.SetElementPropertyString = ToExternal<string, string, string>( "_id", "_key", "_value", "document.getElementById(_id)[_key] = _value;" ); this.GetGlobalPropertyString = ToExternalConverter<string, string, string>( "_id", "_key", "return window[_id][_key];" ); this.SetGlobalPropertyString = ToExternal<string, string, string>( "_id", "_key", "_value", "window[_id][_key] = _value;" ); this.ExternalContext_IHTMLDocument_createElement = ToExternal<string, string>( "_tag", "_i", "window[_i] = document.createElement(_tag);" ); this.ExternalContext_IHTMLDocument_get_body = ToExternal<string>( "_i", "window[_i] = document.body;" ); this.ExternalContext_IHTMLElement_set_innerHTML = ToExternal<string, string>( "_value", "_i", "window[_i].innerHTML = _value;" ); this.ExternalContext_IHTMLElement_appendChild = ToExternal<string, string>( "_parent", "_child", "window[_parent].appendChild(window[_child]);" ); this.ExternalContext_getElementById_call_string = ToExternal<string, string, string>( "_i", "_f", "_a0", "document.getElementById(_i)[_f](_a0);" ); this.ExternalContext_getElementById_call_string_string = ToExternal<string, string, string, string>( "_i", "_f", "_a0", "_a1", "document.getElementById(_i)[_f](_a0, _a1);" ); this.ExternalContext_getElementById_call_string_string_string = ToExternal<string, string, string, string, string>( "_i", "_f", "_a0", "_a1", "_a2", "document.getElementById(_i)[_f](_a0, _a1, _a2);" ); this.ExternalContext_token_call_string = ToExternal<string, string, string>( "_i", "_f", "_a0", "window[_i][_f](_a0);" ); this.ExternalContext_token_call_token = ToExternal<string, string, string>( "_i", "_f", "_j", "window[_i][_f](window[_j]);" ); this.ExternalContext_token_call_string_string_string = ToExternal<string, string, string, string, string>( "_i", "_f", "_a0", "_a1", "_a2", "window[_i][_f](_a0, _a1, _a2);" ); this.ExternalContext_token_set_property = ToExternal<string, string, object>( "_i", "_f", "_v", "window[_i][_f] = _v;" ); this.ExternalContext_getElementById_call = ToExternal<string, string>( "_i", "_f", "document.getElementById(_i)[_f]();" ); this.ExternalContext_token_call = ToExternal<string, string>( "_i", "_f", "window[_i][_f]();" ); this.ExternalContext_token_set_getElementById = ToExternal<string, string>( "_r", "_i", "window[_r] = document.getElementById(_i);" ); this.ExternalContext_let_token_get_property = ToExternal<string, string, string>( "_r", "_i", "_p", "window[_r] = window[_i][_p];" ); #region add_event // http://mihai.bazon.net/blog/flash-s-externalinterface-and-ie // http://swfupload.org/forum/generaldiscussion/985 // ie is unable to load flash external interface if the object was created by innerHTML this.ExternalContext_getElementById_add_event = ToExternal<string, string, string, string>( "_i", "_f", "_j", "_h", // attachEvent = on // @" // var _element = document.getElementById(_i); // if ('attachEvent' in _element) alert('ie event'); // else if ('addEventListener' in _element) alert('ff event'); // " @" var _element = document.getElementById(_i); if ('addEventListener' in _element) { _element.addEventListener(_f, function () { document.getElementById(_j)[_h](); }, false ); } " ); this.ExternalContext_token_add_event = ToExternal<string, string, string, string>( "_i", "_f", "_j", "_h", // attachEvent = on // @" // var _element = document.getElementById(_i); // if ('attachEvent' in _element) alert('ie event'); // else if ('addEventListener' in _element) alert('ff event'); // " @" var _element = window[_i]; if ('addEventListener' in _element) { _element.addEventListener(_f, function () { document.getElementById(_j)[_h](); }, false ); } " ); #endregion }