我正在使用以下代码在 Flash 游戏中显示广告。除了一个小问题外,它工作得很好。如果在显示广告之前调用 startButton 函数,我会收到一条错误消息:
ArgumentError:错误 #2025:提供的 DisplayObject 必须是调用者的子对象。在 flash.display::DisplayObjectContainer/removeChild() 在 VirusDefender/clickStart()[VirusDefender::frame1:17]
广告在舞台上时没有错误。我尝试将 removeChild 包装在 try catch 中,但这不起作用。
如果广告尚未显示,有人可以告诉我如何防止 removeChild 行被调用。有时广告需要长达 3 秒的时间才能显示,因此人们可能会在它上台之前点击。
stop();
//Start Button
startScreen.startButton.addEventListener(MouseEvent.CLICK,clickStart);
function clickStart(event:MouseEvent)
{
sndFire=new fire_sound();
sndFireChannel=sndFire.play();
removeChild(l);
gotoAndStop("play");
}
// Help Button
startScreen.helpButton.addEventListener(MouseEvent.CLICK,clickHelp);
function clickHelp(event:MouseEvent)
{
sndFire=new fire_sound();
sndFireChannel=sndFire.play();
removeChild(l);
gotoAndStop("help");
}
// SMAATO Advertising Code for Start Page
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();
var l:Loader = new Loader();
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();
l.load(new URLRequest(link));
addChild(l);
l.x = 135;
l.y = 265;
var clickurl:String = ad.*::action.@target.toString();
l.addEventListener(MouseEvent.CLICK, onAdClick);
}
function onAdClick(e:MouseEvent):void
{
var request:URLRequest = new URLRequest(clickurl);
navigateToURL(request);
}
}
谢谢!富有的