public MochiAdOptions()
        {
            Data = new DynamicContainer { Subject = new object() };

            ad_finished = delegate { };
            ad_started = delegate { };
        }
        public void Invoke(string connectionName, string data = "", string methodName = "Invoke")
        {
            // wait for ack!

            #region rx
            if (rx == null)
            {
                rx = new LocalConnection();


                var client = new DynamicContainer { Subject = new object() };

                Action<string> Invoke = ack_data =>
                {
                    // http://livedocs.adobe.com/flex/3/html/help.html?content=17_Networking_and_communications_4.html

                    if (yield != null)
                        yield(ack_data);

                    //content.r.Fill = Brushes.Green;
                };

                // http://stackoverflow.com/questions/6834455/as3-localconnection-errors
                client["Invoke"] = Invoke.ToFunction();
                rx.allowDomain("*");
                rx.allowInsecureDomain("*");
                rx.status += delegate
                { };

                rx.client = client.Subject;

                // ArgumentError: Error #2082: Connect failed because the object is already connected.
                // Error #2044: Unhandled StatusEvent:. level=error, code=

                // If the string for connectionName begins with an underscore (for example, _connectionName), Flash Player 
                // does not add a prefix to the string. This means the receiving and sending LocalConnection objects will 
                // use identical strings for connectionName. If the receiving object uses LocalConnection.allowDomain() to specify that connections from any domain will be accepted, you can move the SWF file with the receiving LocalConnection object to another domain without altering any sending LocalConnection objects.
                rx.connect(connectionName + "_ack");

                //content.MouseLeftButtonUp +=
                //    delegate
                //    {
            }
            #endregion


            #region tx
            tx.status +=
                delegate
                {

                };
            tx.allowDomain("*");
            tx.allowInsecureDomain("*");
            tx.send(connectionName, methodName, data);
            #endregion

        }
        public ApplicationSprite()
        {
            this.InvokeWhenStageIsReady(
                () =>
                {
                    content.AttachToContainer(this);
                    content.AutoSizeTo(this.stage);


                    // http://fcontheweb.com/articles/localconnection/
                    var r = new Random();

                    var ii = r.Next(16);

                    c.allowDomain("*");
                    c.allowInsecureDomain("*");
                    c.status += delegate
                    { };

                    content.MouseLeftButtonUp +=
                        delegate
                        {
                            content.r.Fill = Brushes.Yellow;

                            for (int i = 0; i < 16; i++)
                            {
                                c.send("LocalConnectionExperiment" + i, "Invoke", "data");
                            }
                            c.send("Invoke756613399", "Invoke", "data");
                        };



                    var client = new DynamicContainer { Subject = new object() };

                    Action MouseLeftButtonUp = delegate
                    {
                        content.r.Fill = Brushes.Green;

                    };

                    // http://stackoverflow.com/questions/6834455/as3-localconnection-errors
                    client["Invoke"] = MouseLeftButtonUp.ToFunction();

                    rx.status += delegate
                    { };

                    rx.client = client.Subject;

                    // ArgumentError: Error #2082: Connect failed because the object is already connected.
                    // Error #2044: Unhandled StatusEvent:. level=error, code=
                    rx.connect("LocalConnectionExperiment" + ii);
                }
            );
        }
		/// <summary>
		/// Default constructor
		/// </summary>
		public URLRequestHeaderExample()
		{
			// http://livedocs.adobe.com/flex/3/langref/flash/net/URLRequestHeader.html#includeExamplesSummary
			// http://www.judahfrangipane.com/blog/?p=87

			var t = new TextField
			{
				multiline = true,
				text = "powered by jsc",
				background = true,
				width = 400,
				x = 8,
				y = 8,
				alwaysShowSelection = true,
			}.AttachTo(this);

			var loader = new URLLoader();

			var header = new URLRequestHeader("XMyHeader", "got milk?");

			t.appendText("\n" + this.loaderInfo.url);
			t.appendText("\nUsing relative path...");

			var request = new URLRequest("../WebForm1.aspx");
			var data = new DynamicContainer { Subject = new URLVariables("name=John+Doe") };
			data["age"] = 23;

			request.data = data.Subject;
			request.method = URLRequestMethod.POST;
			request.requestHeaders.push(header);

			loader.complete +=
				args =>
				{
					t.appendText("\n" + loader.data);
				};

			loader.load(request);



			KnownEmbeddedResources.Default[KnownAssets.Path.Assets + "/Preview.png"].ToBitmapAsset().AttachTo(this).MoveTo(100, 200);
		}
        public ShopExperience(Sprite that)
        {
            var currentped = default(IPhysicalUnit);

            var shopcontent = new ApplicationCanvas();
            var sb = new Soundboard();

            #region GiveMeWhatIWant
            Action GiveMeWhatIWant = delegate
            {
                shopcontent.bg_ammo.Fill = Brushes.Green;
                shopcontent.bg_shotgun.Fill = Brushes.Green;
                sb.snd_SelectWeapon.play();
                shopcontent.t2o.Opacity = 0.1;
                (currentped as PhysicalPed).With(
                    ped =>
                    {
                        ped.visual.StandWithVisibleGun = true;
                    }
                );
            };

            #endregion

            #region BuyAmmo
            shopcontent.BuyAmmo += delegate
            {
                Console.WriteLine("BuyAmmo");

                //                BuyAmmo
                //facebookOAuthConnectPopup: { facebookOAuthConnectPopup_window = _blank }
                //after facebookOAuthConnectPopup
                //still in window: { Right = 739, Left = 675 }
                //{ zombie_forceA = 4.867357484065154 }
                //facebookOAuthConnectPopup callback { connectUserId = fb1527339800, access_token = AAADLSABgZCZC0BAOroZC3jsNhsgRVFhBK4VcAT19uePwd2iZBKX8ZCVwtdu8ZBhtmU9bH6nMJHO0qJ6I5dzvhw9Ty1kt542zpH2BZCMKKPI0wZDZD, facebookuserid = 1527339800 }
                //at callback
                //BuyAmmo { facebookuserid = 1527339800, Length = 1 }
                //{ item = [playerio.VaultItem][itemKey="Shotgun3", id="403939388", purchaseDate=Mon Mar 11 21:32:08 GMT+0200 2013] = {
                //FreelyGivable:true
                //PriceUSD:99
                //} }
                //set facebookOAuthConnectPopupItems_cache


                sb.snd_click.play(
                      sndTransform: new ScriptCoreLib.ActionScript.flash.media.SoundTransform(0.5)
                  );



#if FFACEBOOK
                that.facebookOAuthConnectPopupItems(
                    (Client xclient, string access_token, string facebookuserid, object[] items) =>
                    {
                        Console.WriteLine("BuyAmmo  " + new { facebookuserid, xclient.payVault.items.Length });

                #region itemKey_exists
                        var itemKey = "Shotgun3";
                        var itemKey_exists = false;

                        foreach (var item in items)
                        {
                            var dyn = new DynamicContainer { Subject = item };

                            var dyn_itemKey = (string)dyn["itemKey"];

                            Console.WriteLine(new { item });

                            if (dyn_itemKey == itemKey)
                                itemKey_exists = true;
                        }

                        if (itemKey_exists)
                        {
                            GiveMeWhatIWant();
                            return;
                        }
                        #endregion


                        //                              facebookOAuthConnectPopup callback { connectUserId = fb1527339800, access_token = AAADLSABgZCZC0BAOroZC3jsNhsgRVFhBK4VcAT19uePwd2iZBKX8ZCVwtdu8ZBhtmU9bH6nMJHO0qJ6I5dzvhw9Ty1kt542zpH2BZCMKKPI0wZDZD, facebookuserid = 1527339800 }
                        //BuyAmmo { facebookuserid = 1527339800, Length = 1 }
                        //{ item = [playerio.VaultItem][itemKey="Shotgun3", id="403939388", purchaseDate=Mon Mar 11 21:32:08 GMT+0200 2013] = {
                        //FreelyGivable:true
                        //PriceUSD:99
                        //} }

                    }
                );
#endif

            };
            #endregion

            #region BuyShotgun
            shopcontent.BuyShotgun += delegate
            {
                Console.WriteLine("BuyShotgun");

                sb.snd_click.play(
                  sndTransform: new ScriptCoreLib.ActionScript.flash.media.SoundTransform(0.5)
              );


              //  that.facebookOAuthConnectPopupItems(
              //    (Client xclient, string access_token, string facebookuserid, object[] items) =>
              //    {
              //        Console.WriteLine("BuyShotgun  " + new { facebookuserid, xclient.payVault.items.Length });

              //        var itemKey = "Shotgun3";


              //        var BuyAnyway = false;
              //        if (BuyAnyway)
              //        {

              //        }
              //        else
              //        {

              //            #region itemKey_exists
              //            var itemKey_exists = false;

              //            foreach (var item in items)
              //            {
              //                var dyn = new DynamicContainer { Subject = item };

              //                var dyn_itemKey = (string)dyn["itemKey"];

              //                Console.WriteLine(new { item });

              //                if (dyn_itemKey == itemKey)
              //                    itemKey_exists = true;
              //            }

              //            if (itemKey_exists)
              //            {
              //                GiveMeWhatIWant();

              //                return;
              //            }
              //            #endregion

              //        }

              //        Console.WriteLine("before getBuyDirectInfo");

              //        //// Gets information about how to make a direct item purchase with the specified PayVault provider.
              //        //that.getBuyDirectInfo(
              //        //    xclient,
              //        //    facebookuserid,

              //        //    item_name: "Operation Heat Zeeker - Shotgun",
              //        //    itemKey: itemKey,

              //        //    yield_paypalurl: uri =>
              //        //    {
              //        //        Console.WriteLine("at getBuyDirectInfo");

              //        //        shopcontent.bg_shotgun.Fill = Brushes.Red;


              //        //        uri.NavigateTo();
              //        //    }
              //        //);


              //    }
              //);


            };
            #endregion


            ShopEnter =
                ped =>
                {
                    currentped = ped;


                    shopcontent.AttachToContainer(that);
                    shopcontent.AutoSizeTo(that.stage);
                };


            shopcontent.Close += delegate
            {
                if (currentped == null)
                    return;

                currentped = null;

                ScriptCoreLib.ActionScript.Extensions.CommonExtensions.Orphanize(
                    ScriptCoreLib.ActionScript.Extensions.AvalonExtensions.ToSprite(shopcontent)
                    );
            };

            ShopExit =
               delegate
               {
                   if (currentped == null)
                       return;

                   currentped = null;

                   ScriptCoreLib.ActionScript.Extensions.CommonExtensions.Orphanize(
                       ScriptCoreLib.ActionScript.Extensions.AvalonExtensions.ToSprite(shopcontent)
                       );
               };
        }
        public static void getBuyDirectInfo(this Sprite that,
            Client client, string facebookuserid,

            string item_name = "Operation Heat Zeeker - Shotgun",
            string itemKey = "Shotgun3",

            Action<Uri> yield_paypalurl = null
            )
        {
            Console.WriteLine("before getBuyDirectInfo " + new { client.connectUserId, facebookuserid });

            // error: { errorID = 0, error = NotImplementedException: __CallSite.Create, e = [UncaughtErrorEvent type="uncaughtError" bubbles=true cancelable=true eventPhase=2] }

            var purchaseArguments = new DynamicContainer { Subject = new object() };

            purchaseArguments["currency"] = "USD";
            purchaseArguments["item_name"] = item_name + " [for http://www.facebook.com/profile.php?id=" + facebookuserid + "]";

            var item = new item_object();

            // .99 USD
            item.itemKey = itemKey;

            var items = new object[] { item };

            Action<dynamic> callback = info =>
            {
                string paypalurl = info.paypalurl;

                Console.WriteLine("getBuyDirectInfo callback " + new { paypalurl });

                var uri = new Uri(paypalurl);

                if (yield_paypalurl != null)
                    yield_paypalurl(uri);
            };

            Action<PlayerIOError> errorHandler = e =>
            {
                Console.WriteLine("getBuyDirectInfo errorHandler " + e);


                //that.content.bg_shotgun.Fill = System.Windows.Media.Brushes.Red;
            };


            Console.WriteLine("just before getBuyDirectInfo");

            // error: { errorID = 0, message = Unable to connect to the API due to securityError. Please verify that your internet connection is working! }
            // getBuyDirectInfo errorHandler Error: Items with keys [shotgun1] do not exist in PayVaultItems
            // etBuyDirectInfo errorHandler Error: Missing 'currency' in purchaseArguments. It should be a currency code supported by PayPal, such as 'USD'. The price is found in the PayVault items property 'Price[currency]', such as 'PriceUSD'

            client.payVault.getBuyDirectInfo(
                provider: "paypal",
                purchaseArguments: purchaseArguments.Subject,
                items: items,
                callback: callback.ToFunction(),
                errorHandler: errorHandler.ToFunction()
            );

            Console.WriteLine("after getBuyDirectInfo");
        }
        //C:\util\flex_sdk_4.6\frameworks\flex-config.xml(47): Error: unable to open 'libs/player/11.1/playerglobal.swc'


        // http://www.adobe.com/devnet/flashplayer/articles/rtmfp_stratus_app_03.html

        // see this video:
        // http://tv.adobe.com/#vi+f15384v1056

        /// <summary>
        /// Default constructor
        /// </summary>
        public FlashStratusDemo()
        {

            var t = new TextField
            {
                multiline = true,
                text = "powered by jsc",
                background = true,
                x = 0,
                y = 0,
                width = 400,
                alwaysShowSelection = true,
            }.AttachTo(this);

            var c = new NetConnection();



            Func<NetStatusEvent, string> get_Code =
                e =>
                {
                    var info = new DynamicContainer { Subject = e.info };
                    var code = (string)info["code"];

                    return code;
                };


            c.netStatus +=
                status =>
                {
                    // http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/events/NetStatusEvent.html#info


                    t.appendText("\nc.netStatus: " + get_Code(status));

                    if (get_Code(status) == "NetConnection.Connect.Success")
                    {
                        t.appendText("\n" + c.nearID);

                        #region we could be a client

                        var q = new TextField
                        {
                            background = true,
                            x = 0,
                            y = 200,
                            width = 400,
                            alwaysShowSelection = true,
                            text = "enter id here",
                            type = TextFieldType.INPUT
                        }.AttachTo(this);


                        q.change +=
                            delegate
                            {
                                if (q.text.Length != c.nearID.Length)
                                    return;

                                if (q.text == c.nearID)
                                    return;

                                t.appendText("\ntarget set");
                                q.Orphanize();

                                var r = new NetStream(c, q.text);

                                r.netStatus +=
                                    r_status =>
                                    {

                                        t.appendText("\nr.netStatus: " + get_Code(r_status));
                                    };

                                r.client = new DynamicDelegatesContainer
									{
										{"handler1", 
											(string x) =>
											{
												t.appendText("\nhandler1: " + x);
												t.setSelection( t.length, t.length);
											}
										}
									}.Subject;

                                r.play("stream1");
                            };
                        #endregion

                        // yay! we are online
                        var s = new NetStream(c, NetStream.DIRECT_CONNECTIONS);

                        s.client = new DynamicDelegatesContainer
						{
							{"onPeerConnect", 
								(NetStream x) =>
								{
									
									t.appendText("\nonPeerConnect: " + x.farID);
									t.setSelection( t.length, t.length);

									q.Orphanize();

									return true;
								}
							}
						}.Subject;

                        s.netStatus +=
                            s_status =>
                            {

                                t.appendText("\ns.netStatus: " + get_Code(s_status));
                            };









                        s.publish("stream1");

                        #region broadcast the data
                        var counter = 0;

                        5000.AtInterval(
                            delegate
                            {
                                counter++;

                                s.send("handler1", "counter = " + counter);
                            }
                        );
                        #endregion

                    }
                };




            // "Developer Key" means any license key, activation code, or similar 
            // installation, access or usage control codes, including serial numbers 
            // and electronic certificates digitally signed by Adobe, designed to 
            // uniquely identify your Developer Program and link it to you 
            // the Developer.

            // Attention: You cannot use this key in your applications.
            //c.connect("rtmfp://stratus.adobe.com/3f37a156abb67621000856d1-08d2970f1b43/");
            c.connect("rtmfp://stratus.adobe.com/3f37a156abb67621000856d1-08d2970f1b43");

            // X:\jsc.svn\examples\actionscript\MultitouchExample\MultitouchFingerTools.FlashLAN\ApplicationCanvas.Session.cs
        }
        public static void InternalInvoke(Action<string> yield)
        {
            #region rx
            if (rx == null)
            {
                rx = new LocalConnection();
                var r = new Random();

                ii = r.Next();


                var client = new DynamicContainer { Subject = new object() };

                Action<string> Invoke = data =>
                {
                    //if (yield == null)
                    //    return;

                    // http://livedocs.adobe.com/flex/3/html/help.html?content=17_Networking_and_communications_4.html
                    //Diagnostics("InternalInvoke yield");

                    yield(data);
                    //yield = null;

                    //content.r.Fill = Brushes.Green;
                };

                // http://stackoverflow.com/questions/6834455/as3-localconnection-errors
                client["Invoke"] = Invoke.ToFunction();
                rx.allowDomain("*");
                rx.allowInsecureDomain("*");
                rx.status += delegate
                { };

                rx.client = client.Subject;

                // ArgumentError: Error #2082: Connect failed because the object is already connected.
                // Error #2044: Unhandled StatusEvent:. level=error, code=

                // If the string for connectionName begins with an underscore (for example, _connectionName), Flash Player 
                // does not add a prefix to the string. This means the receiving and sending LocalConnection objects will 
                // use identical strings for connectionName. If the receiving object uses LocalConnection.allowDomain() to specify that connections from any domain will be accepted, you can move the SWF file with the receiving LocalConnection object to another domain without altering any sending LocalConnection objects.
                rx.connect("_Invoke" + ii);

                //content.MouseLeftButtonUp +=
                //    delegate
                //    {
            }
            #endregion

            Diagnostics("NavigateTo");
            new Uri("http://young-beach-4377.herokuapp.com/#c" + ii).NavigateTo();
            //};
        }
예제 #9
0
        public Task<byte[]> UploadValuesTaskAsync(Uri address, NameValueCollection data)
        {
            // X:\jsc.svn\examples\actionscript\Test\TestWorkerUploadValuesTaskAsync\TestWorkerUploadValuesTaskAsync\ApplicationSprite.cs
            // https://forums.adobe.com/thread/1189679

            var xx = new TaskCompletionSource<byte[]>();

            // X:\jsc.svn\examples\actionscript\Test\TestUploadValuesTaskAsync\TestUploadValuesTaskAsync\ApplicationSprite.cs

            var request = new URLRequest(address.ToString())
            {
                method = URLRequestMethod.POST
            };

            // should we use dynamic instead?
            var x = new DynamicContainer { Subject = new URLVariables() };

            foreach (var item in data.AllKeys)
            {
                x[item] = data[item];
            }

            // http://stackoverflow.com/questions/12774611/urlrequest-urlloader-auto-converting-post-request-to-get
            // !!!!
            request.data = (object)x.Subject;
            //request.contentType = ""

            var loader = new URLLoader();
            // http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLLoaderDataFormat.html
            //loader.dataFormat = URLLoaderDataFormat.Binary;
            loader.dataFormat = "binary";
            // http://stackoverflow.com/questions/7816231/how-to-use-as3-to-load-binary-data-from-web-server

            loader.complete +=
                args =>
                {
                    // If the dataFormat property is URLLoaderDataFormat.BINARY, the received data is a ByteArray object 
                    // containing the raw binary data.

                    //                TypeError: Error #1034: Type Coercion failed: cannot convert ScriptCoreLib.Shared.BCLImplementation.System.Net::__DownloadStringCompletedEventArgs@5422ad9 to ScriptCoreLib.Shared.BCLImplementation.System.Net.__UploadValuesCompletedEventArgs.
                    //at ScriptCoreLib.ActionScript.BCLImplementation.System.Net::__WebClient/_UploadValuesAsync_b__7_4ebbe596_06000fb2()[V:\web\ScriptCoreLib\ActionScript\BCLImplementation\System\Net\__WebClient.as:143]
                    //at flash.events::EventDispatcher/dispatchEventFunction()
                    //at flash.events::EventDispatcher/dispatchEvent()
                    //at flash.net::URLLoader/redirectEvent()

                    // TypeError: Error #1034: Type Coercion failed: cannot convert ScriptCoreLib.Shared.BCLImplementation.System.Net::__DownloadStringCompletedEventArgs@53686e9 to ScriptCoreLib.Shared.BCLImplementation.System.Net.__UploadValuesCompletedEventArgs.

                    //throw new Exception(
                    //    new { loader.data, loader.dataFormat, t = loader.data.GetType() }.ToString()
                    //);

                    var bytes = (ByteArray)loader.data;
                    var Result = (byte[])bytes.ToArray();

                    //if (UploadValuesCompleted != null)
                    //    UploadValuesCompleted(this, (UploadValuesCompletedEventArgs)(object)e);

                    xx.SetResult(Result);
                };

            loader.ioError +=
                args =>
                {
                    var e = new __UploadValuesCompletedEventArgs { Error = new Exception("ioError") };
                    //if (UploadValuesCompleted != null)
                    //    UploadValuesCompleted(this, (UploadValuesCompletedEventArgs)(object)e);

                    throw e.Error;
                };


            loader.securityError +=
                args =>
                {
                    var e = new __UploadValuesCompletedEventArgs
                    {
                        Error = new Exception(
                            "securityError " + new { args.errorID, args.text }
                            )
                    };

                    //if (UploadValuesCompleted != null)
                    //    UploadValuesCompleted(this, (UploadValuesCompletedEventArgs)(object)e);

                    throw e.Error;
                };

            loader.load(request);

            return xx.Task;
        }
		public MochiScoresOptions()
        {
            Data = new DynamicContainer { Subject = new object() };

        }