AS3 - 消除子问题

发布于 2024-11-16 05:54:15 字数 1437 浏览 6 评论 0原文

我正在使用以下代码在我正在开发的手机游戏中显示广告。它工作正常,但我不知道在 clickStart 函数中添加什么来在游戏开始前从舞台上删除广告。我一直在玩removeChild,但似乎无法让它工作。

stop();
startButton.addEventListener(MouseEvent.CLICK,clickStart);

function clickStart(event:MouseEvent) {
gotoAndStop("play");
}


var request:URLRequest = new URLRequest("http://soma.smaato.com/oapi/reqAd.jsp");
var variables:URLVariables = new URLVariables();
variables.adspace = "0";
variables.pub = "0";

variables.devip = "127.0.0.1";
variables.format = "IMG";
variables.adcount = "1";
variables.response = "XML";
request.data = variables;
var loader:URLLoader = new URLLoader();

loader.addEventListener(Event.COMPLETE, onComplete);
loader.load(request);


function onComplete(e:Event):void
{
var data:XML = new XML(loader.data as String);
var status:String = data.*::status.toString();
    if(status == "success")
    {
    var ad:XMLList = data.*::ads.*::ad;
    var link:String = ad.*::link.toString();

    var l:Loader = new Loader();
    l.load(new URLRequest(link));
    addChild(l);
l.x = 135;
l.y = 265;
    var clickurl:String = ad.*::[email protected]();
    l.addEventListener(MouseEvent.CLICK, onAdClick);

    function onAdClick(e:MouseEvent):void
    {
    var request:URLRequest = new URLRequest(clickurl);
    navigateToURL(request);
    }

  }
}

I'm using the following code to display an advertisement in a mobile game that I'm working on. It works fine but I don't know what to put in the clickStart function to remove the advertisement from the stage before the game plays. I've been playing around with removeChild but can't seem to get it to work.

stop();
startButton.addEventListener(MouseEvent.CLICK,clickStart);

function clickStart(event:MouseEvent) {
gotoAndStop("play");
}


var request:URLRequest = new URLRequest("http://soma.smaato.com/oapi/reqAd.jsp");
var variables:URLVariables = new URLVariables();
variables.adspace = "0";
variables.pub = "0";

variables.devip = "127.0.0.1";
variables.format = "IMG";
variables.adcount = "1";
variables.response = "XML";
request.data = variables;
var loader:URLLoader = new URLLoader();

loader.addEventListener(Event.COMPLETE, onComplete);
loader.load(request);


function onComplete(e:Event):void
{
var data:XML = new XML(loader.data as String);
var status:String = data.*::status.toString();
    if(status == "success")
    {
    var ad:XMLList = data.*::ads.*::ad;
    var link:String = ad.*::link.toString();

    var l:Loader = new Loader();
    l.load(new URLRequest(link));
    addChild(l);
l.x = 135;
l.y = 265;
    var clickurl:String = ad.*::[email protected]();
    l.addEventListener(MouseEvent.CLICK, onAdClick);

    function onAdClick(e:MouseEvent):void
    {
    var request:URLRequest = new URLRequest(clickurl);
    navigateToURL(request);
    }

  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深海里的那抹蓝 2024-11-23 05:54:15

您需要将 Loader 的声明移到 onComplete 函数之外,因为变量超出了范围。

var l:Loader = new Loader();

您可以尝试将其放在与这些相同的范围内:

var request:URLRequest = new URLRequest("http://soma.smaato.com/oapi/reqAd.jsp");
var variables:URLVariables = new URLVariables();

然后您应该能够将 clickStart 函数更新为如下所示:

function clickStart(event:MouseEvent) {
removeChild(l);
gotoAndStop("play");
}

You need to move the declaration of the Loader outside of the onComplete function, since the variable runs out of scope.

var l:Loader = new Loader();

You could try placing it on the same scope as these:

var request:URLRequest = new URLRequest("http://soma.smaato.com/oapi/reqAd.jsp");
var variables:URLVariables = new URLVariables();

then you should be able to update your clickStart function to something like this:

function clickStart(event:MouseEvent) {
removeChild(l);
gotoAndStop("play");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文