我使用的SWF(ACCUEIL)另一个SWF(ranchleblanc_fr)的内部,这将导致错误1009显示:错误#1009,动作3
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at accueil_fla::MainTimeline/frame1()"
第一SWF具有在它和它的颗粒的效果我第一次加载页面时不会启动。如果我点击主页面的任何按钮并返回到accueil页面,效果就起作用。但是如果我再次点击另一个按钮,我会得到另一个错误1009,但这次它不仅会出现一次。它一遍又一遍地出现,直到我关闭SWF。
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at accueil_fla::MainTimeline/newFlake()"
我将包含的代码,但我做之前,我必须说,我选中该复选框以允许在发布设置调试,我没有行号查找错误。我用了踪迹,发现null
变量是flake
。我搜索了互联网,找出如何解决我的问题,我想我需要使用if语句,因此请确保程序以null
变量运行。我想我应该检查片状变量是否为null
,如果是,则声明某种价值。
的问题是,我不知道如何编写一个if语句...
这里是我的accueil_fla代码,第1帧(所有这FLA的行动可以找到)
for (var i:uint = 0; i < 50; i++)
{
flake.x = Math.random() * stage.stageWidth;
flake.y = Math.random() * stage.stageHeight;
flake.alpha = randRange(.3,1);
flake.scaleX = flake.scaleY = randRange(.3,1);
addChild(flake);
}
function randRange(low:Number, high:Number):Number
{
var randNum:Number = Math.random() * (high - low) + low;
return randNum;
}
this.addEventListener(Event.ENTER_FRAME, newFlake);
function newFlake(e:Event):void
{
var flake:Snowflake = new Snowflake(randRange(-1,1), randRange(2,5));
flake.x = Math.random() * stage.stageWidth;
flake.y = -5;
flake.alpha = randRange(.3,1);
flake.scaleX = flake.scaleY = randRange(.3,1);
addChild(flake);
}
var flake:Snowflake = new Snowflake(randRange(-1,1), randRange(2,5));
我还可以包含主页面的代码,以解决雪粒效应在第一次加载时不起作用的原因。
//----------------initialization---------------\\
extLoader_mc.visible = false;
//--------------------loader------------------------\\
var loader:Loader = new Loader;
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, preload);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, done);
function preload (e:ProgressEvent):void
{
extLoader_mc.visible = true;
var pct:Number = e.bytesLoaded/e.bytesTotal;
extLoader_mc.extLoaderBar_mc.scaleX = pct;
}
function done (e:Event):void
{
extLoader_mc.visible = false;
canvas_mc.addChild(loader);
}
//-----------------------end loader----------------\\
var firstLoad:URLRequest = new URLRequest("accueil.swf");
loader.load(firstLoad);
var currentPage:MovieClip;
currentPage=accueil_mc;
currentPage.gotoAndPlay("down");
accueilHit_mc.targetmc = accueil_mc;
aProposHit_mc.targetmc = aPropos_mc;
animauxHit_mc.targetmc = animaux_mc;
locationHit_mc.targetmc = location_mc;
contactHit_mc.targetmc = contact_mc;
accueilHit_mc.buttonMode = true;
aProposHit_mc.buttonMode = true;
animauxHit_mc.buttonMode = true;
locationHit_mc.buttonMode = true;
contactHit_mc.buttonMode = true;
function el()
{
accueilHit_mc.addEventListener(MouseEvent.CLICK, accueilPage);
accueilHit_mc.addEventListener(MouseEvent.MOUSE_OVER, btnOver);
accueilHit_mc.addEventListener(MouseEvent.MOUSE_OUT, btnOut);
//aProposHit_mc.addEventListener(MouseEvent.CLICK, aProposPage);
aProposHit_mc.addEventListener(MouseEvent.MOUSE_OVER, btnOver);
aProposHit_mc.addEventListener(MouseEvent.MOUSE_OUT, btnOut);
//animauxHit_mc.addEventListener(MouseEvent.CLICK, animauxPage);
animauxHit_mc.addEventListener(MouseEvent.MOUSE_OVER, btnOver);
animauxHit_mc.addEventListener(MouseEvent.MOUSE_OUT, btnOut);
locationHit_mc.addEventListener(MouseEvent.CLICK, locationPage);
locationHit_mc.addEventListener(MouseEvent.MOUSE_OVER, btnOver);
locationHit_mc.addEventListener(MouseEvent.MOUSE_OUT, btnOut);
contactHit_mc.addEventListener(MouseEvent.CLICK, contactPage);
contactHit_mc.addEventListener(MouseEvent.MOUSE_OVER, btnOver);
contactHit_mc.addEventListener(MouseEvent.MOUSE_OUT,btnOut);
}
function btnOver (e:MouseEvent):void
{
e.currentTarget.targetmc.gotoAndPlay("over");
}
function btnOut (e:MouseEvent):void
{
e.currentTarget.targetmc.gotoAndPlay("out");
}
function handCursor()
{
accueilHit_mc.useHandCursor = true;
aProposHit_mc.useHandCursor = true;
animauxHit_mc.useHandCursor = true;
locationHit_mc.useHandCursor = true;
contactHit_mc.useHandCursor = true;
accueilHit_mc.enabled = true;
aProposHit_mc.enabled = true;
animauxHit_mc.enabled = true;
locationHit_mc.enabled = true;
contactHit_mc.enabled = true;
}
el();
accueilHit_mc.removeEventListener(MouseEvent.CLICK, accueilPage);
accueilHit_mc.removeEventListener(MouseEvent.MOUSE_OVER, btnOver);
accueilHit_mc.removeEventListener(MouseEvent.MOUSE_OUT, btnOut);
handCursor();
accueilHit_mc.useHandCursor = false;
accueilHit_mc.enabled = false;
function accueilPage (e:MouseEvent):void
{
currentPage.gotoAndPlay("out");
var req:URLRequest = new URLRequest("accueil.swf");
loader.load(req);
el();
accueilHit_mc.removeEventListener(MouseEvent.CLICK, accueilPage);
handCursor();
accueilHit_mc.useHandCursor = false;
accueilHit_mc.enabled = false;
accueilHit_mc.removeEventListener(MouseEvent.MOUSE_OVER, btnOver);
accueilHit_mc.removeEventListener(MouseEvent.MOUSE_OUT, btnOut);
accueil_mc.gotoAndStop("down");
currentPage=accueil_mc;
}
function aProposPage (e:MouseEvent):void
{
currentPage.gotoAndPlay("out");
var req:URLRequest = new URLRequest("aPropos.swf");
loader.load(req);
el();
aProposHit_mc.removeEventListener(MouseEvent.CLICK, aProposPage);
handCursor();
aProposHit_mc.useHandCursor = false;
aProposHit_mc.enabled = false;
aProposHit_mc.removeEventListener(MouseEvent.MOUSE_OVER, btnOver);
aProposHit_mc.removeEventListener(MouseEvent.MOUSE_OUT, btnOut);
aPropos_mc.gotoAndStop("down");
currentPage=aPropos_mc;
}
function animauxPage (e:MouseEvent):void
{
currentPage.gotoAndPlay("out");
var req:URLRequest = new URLRequest("animaux_fr.swf");
loader.load(req);
el();
animauxHit_mc.removeEventListener(MouseEvent.CLICK, animauxPage);
handCursor();
animauxHit_mc.useHandCursor = false;
animauxHit_mc.enabled = false;
animauxHit_mc.removeEventListener(MouseEvent.MOUSE_OVER, btnOver);
animauxHit_mc.removeEventListener(MouseEvent.MOUSE_OUT, btnOut);
animaux_mc.gotoAndStop("down");
currentPage=animaux_mc;
}
function locationPage (e:MouseEvent):void
{
currentPage.gotoAndPlay("out");
var req:URLRequest = new URLRequest("location.swf");
loader.load(req);
el();
locationHit_mc.removeEventListener(MouseEvent.CLICK, locationPage);
handCursor();
locationHit_mc.useHandCursor = false;
locationHit_mc.enabled = false;
locationHit_mc.removeEventListener(MouseEvent.MOUSE_OVER, btnOver);
locationHit_mc.removeEventListener(MouseEvent.MOUSE_OUT, btnOut);
location_mc.gotoAndStop("down");
currentPage=location_mc;
}
function contactPage (e:MouseEvent):void
{
currentPage.gotoAndPlay("out");
var req:URLRequest = new URLRequest("contact.swf");
loader.load(req);
el();
contactHit_mc.removeEventListener(MouseEvent.CLICK, contactPage);
handCursor();
contactHit_mc.useHandCursor = false;
contactHit_mc.enabled = false;
contactHit_mc.removeEventListener(MouseEvent.MOUSE_OVER, btnOver);
contactHit_mc.removeEventListener(MouseEvent.MOUSE_OUT, btnOut);
contact_mc.gotoAndStop("down");
currentPage=contact_mc;
}
再次感谢您的帮助,非常感谢。
当你将一个.swf加载到第二个时,那么第一个swf不应该有stage的引用。如果你有阶段引用,则会抛出错误。 – 2012-02-09 06:13:09
嗨,欢迎来到Stack Overflow。首先,虽然它确实让你发布整个代码的意图很好,但它不利于你的问题的可读性 - 这是一个**很多代码可读的内容。此外,重新格式化它是一个痛苦:请注意,SO上的代码编辑器预计空白字符是空格字符,而不是标签... – weltraumpirat 2012-02-09 06:26:19
请在执行stage.stageWidth调用之前跟踪(阶段)。你的舞台可能为空。否则看起来不错! – 2012-02-09 14:20:10