Ejemplo n.º 1
0
        public ApplicationSprite()
        {
            //Security.allowDomain("*");
            //Security.allowInsecureDomain("*");

            this.InvokeWhenStageIsReady(
                () =>
                {

                    var deal = KnownEmbeddedResources.Default[Sounds.Assets.deal];
                    var click = KnownEmbeddedResources.Default[Sounds.Assets.click];
                    var drag = KnownEmbeddedResources.Default[Sounds.Assets.drag];
                    var win = KnownEmbeddedResources.Default[Sounds.Assets.win];

                    content.Sounds.deal = () => deal.ToSoundAsset().play();
                    content.Sounds.click = () => click.ToSoundAsset().play();
                    content.Sounds.drag = () => drag.ToSoundAsset().play();
                    content.Sounds.win = () => win.ToSoundAsset().play();

                    content.AttachToContainer(this);
                    content.AutoSizeTo(this.stage);

                    if (Security.sandboxType == "application")
                    {
                        // AdMob!
                        // mochiAds wont work on Android!
                    }
                    else
                    {

                        var shadow = new Rectangle();

                        shadow.Fill = Brushes.Black;
                        shadow.Width = this.stage.stageWidth;
                        shadow.Height = this.stage.stageHeight;
                        shadow.Opacity = 0.5;

                        content.Children.Add(shadow);

                        var clip = new MovieClip().AttachTo(this);




                        //dynamic options = new object();

                        //options.clip = this;
                        //options.id = "47e72426ba7f4f3f";
                        //options.res = this.stage.stageWidth + "x" + this.stage.stageHeight;
                        //options.ad_finished = a;

                        // Error: MochiAd is missing the 'clip' parameter.  
                        // This should be a MovieClip, Sprite or an instance of a class that extends MovieClip or Sprite.

                        // https://www.mochimedia.com/community/forum/topic/desktop-air-application#46785de6

                        //                SecurityError: Error #2047: Security sandbox violation: parent: http://xs.mochiads.com/container/MochiAdsCDN-AS3.swf?do_init=1&cacheBust=1359132511880 cannot access app:/AvalonCardGames.AIRFreeCell.ApplicationSprite.swf.
                        //at flash.display::DisplayObject/get parent()
                        //at com.mochimedia.targeting::MochiAdsTargeting/removedFromStage()[/home/mochi/src/mochiads_erl/priv/as3/com/mochimedia/targeting/MochiAdsTargeting.as:128]
                        //at flash.display::DisplayObjectContainer/removeChildAt()
                        //at mochi.as3::MochiAd$/_cleanup()[W:\opensource\mochimedia.com\MochiAd.as:946]
                        //at Function/<anonymous>()[W:\opensource\mochimedia.com\MochiAd.as:195]
                        //at mochi.as3::MochiAd$/unload()[W:\opensource\mochimedia.com\MochiAd.as:924]
                        //at Function/<anonymous>()[W:\opensource\mochimedia.com\MochiAd.as:275]
                        //at Function/<anonymous>()[W:\opensource\mochimedia.com\MochiAd.as:41]


                        //                SecurityError: Error #2047: Security sandbox violation: parent: http://xs.mochiads.com/container/MochiAdsCDN-AS3.swf?do_init=1&cacheBust=1359134133659 cannot access app:/AvalonCardGames.AIRFreeCell.ApplicationSprite.swf.
                        //at flash.display::DisplayObject/get parent()
                        //at com.mochimedia.targeting::MochiAdsTargeting/removedFromStage()[/home/mochi/src/mochiads_erl/priv/as3/com/mochimedia/targeting/MochiAdsTargeting.as:128]
                        //at flash.display::DisplayObjectContainer/removeChildAt()
                        //at mochi.as3::MochiAd$/_cleanup()
                        //at MethodInfo-1806()
                        //at mochi.as3::MochiAd$/unload()
                        //at MethodInfo-1807()
                        //at MethodInfo-1793()

                        //    SecurityError: Error #2047: Security sandbox violation: parent: http://xs.mochiads.com/container/MochiAdsCDN-AS3.swf?do_init=1&cacheBust=1359134133659 cannot access app:/AvalonCardGames.AIRFreeCell.ApplicationSprite.swf.
                        //at flash.display::DisplayObject/get parent()
                        //at com.mochimedia.container::MochiAdsContainer/initalize()[/home/mochi/src/mochiads_erl/priv/as3/com/mochimedia/container/MochiAdsContainer.as:40]
                        //at com.mochimedia.targeting::MochiAdsTargeting/onJSONData()[/home/mochi/src/mochiads_erl/priv/as3/com/mochimedia/targeting/MochiAdsTargeting.as:780]
                        //at flash.events::EventDispatcher/dispatchEventFunction()
                        //at flash.events::EventDispatcher/dispatchEvent()
                        //at flash.net::URLLoader/onComplete()



                        var options = new MochiAdOptions
                        {

                            //TypeError: Error #1034: Type Coercion failed: cannot convert AvalonCardGames.AIRFreeCell::ApplicationSprite@14b37041 to flash.display.MovieClip.
                            //    at mochi.as3::MochiAd$/load()[W:\opensource\mochimedia.com\MochiAd.as:789]
                            //    at mochi.as3::MochiAd$/showPreGameAd()[W:\opensource\mochimedia.com\MochiAd.as:185]
                            //    at AvalonCardGames.AIRFreeCell::MochiAdOptions/showPreGameAd_100664136()[U:\web\AvalonCardGames\AIRFreeCell\MochiAdOptions.as:74]
                            //    at AvalonCardGames.AIRFreeCell::ApplicationSprite/__ctor_b__1_100663300()[U:\web\AvalonCardGames\AIRFreeCell\ApplicationSprite.as:82]

                            clip = clip,
                            id = _mochiads_game_id,
                            res = this.stage.stageWidth + "x" + this.stage.stageHeight,


                            ad_finished =
                             delegate
                             {
                                 this.removeChild(clip);

                                 shadow.Orphanize();

                                 {
                                     var now = DateTime.Now;
                                     Console.WriteLine(now + " ready! " + new { Security.sandboxType });
                                 }
                             }
                        };

                        {
                            var now = DateTime.Now;
                            Console.WriteLine(now + " can we get some ads? " + new { Security.sandboxType });
                        }
                        options.showPreGameAd();
                    }
                }
            );


            #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

        }
Ejemplo n.º 2
0
        public ApplicationSprite()
        {
            this.InvokeWhenStageIsReady(
                () =>
                {


                    var deal = KnownEmbeddedResources.Default[Sounds.Assets.deal];
                    var click = KnownEmbeddedResources.Default[Sounds.Assets.click];
                    var drag = KnownEmbeddedResources.Default[Sounds.Assets.drag];
                    var win = KnownEmbeddedResources.Default[Sounds.Assets.win];

                    content.Sounds.deal = () => deal.ToSoundAsset().play();
                    content.Sounds.click = () => click.ToSoundAsset().play();
                    content.Sounds.drag = () => drag.ToSoundAsset().play();
                    content.Sounds.win = () => win.ToSoundAsset().play();

                    content.AttachToContainer(this);
                    content.AutoSizeTo(this.stage);


                    var shadow = new Rectangle();

                    shadow.Fill = Brushes.Black;
                    shadow.Width = this.stage.stageWidth;
                    shadow.Height = this.stage.stageHeight;
                    shadow.Opacity = 0.5;

                    content.Children.Add(shadow);

                    var clip = new MovieClip().AttachTo(this);


                    var options = new MochiAdOptions
                    {

                        //TypeError: Error #1034: Type Coercion failed: cannot convert AvalonCardGames.AIRFreeCell::ApplicationSprite@14b37041 to flash.display.MovieClip.
                        //    at mochi.as3::MochiAd$/load()[W:\opensource\mochimedia.com\MochiAd.as:789]
                        //    at mochi.as3::MochiAd$/showPreGameAd()[W:\opensource\mochimedia.com\MochiAd.as:185]
                        //    at AvalonCardGames.AIRFreeCell::MochiAdOptions/showPreGameAd_100664136()[U:\web\AvalonCardGames\AIRFreeCell\MochiAdOptions.as:74]
                        //    at AvalonCardGames.AIRFreeCell::ApplicationSprite/__ctor_b__1_100663300()[U:\web\AvalonCardGames\AIRFreeCell\ApplicationSprite.as:82]

                        clip = clip,
                        id = _mochiads_game_id,
                        res = this.stage.stageWidth + "x" + this.stage.stageHeight,


                        ad_finished =
                         delegate
                         {
                             this.removeChild(clip);

                             content.Children.Remove(shadow);
                             //shadow.Orphanize();

                             {
                                 var now = DateTime.Now;
                                 Console.WriteLine(now + " ready! " + new { Security.sandboxType });
                             }
                         }
                    };

                    {
                        var now = DateTime.Now;
                        Console.WriteLine(now + " can we get some ads? " + new { Security.sandboxType });
                    }
                    options.showPreGameAd();
                }
            );
        }