错误#1009,ActionScript 3的 [英] Error #1009, ActionScript 3

查看:368
本文介绍了错误#1009,ActionScript 3的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的SWF(ACCUEIL)内的另一个SWF(ranchleblanc_fr),这导致错误1009出现:

I am using a SWF(accueil) inside another SWF(ranchleblanc_fr) and this causes the error 1009 to appear:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at accueil_fla::MainTimeline/frame1()"

第一个SWF中有一个粒子效应,它不会开始当我第一次加载页面。如果我点击主界面中的任何按钮,返回到ACCUEIL页面,效果的作品。但是,如果我再点击另一个按钮,我得到另一个错误1009,但这次它并没有只出现一次。直到我关闭SWF看来一遍又一遍。

The first SWF has a particle effect in it and it won't start when I first load the page. If i click on any button of the main page and return to the accueil page, the effect works. But if I click on another button again, I get another error 1009, but this time it does not only appear once. It appears over and over again until I close the SWF.

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at accueil_fla::MainTimeline/newFlake()"

我将包括code,但在此之前我做什么,我必须说,我检查,以允许调试的发布设置的框,我没有行号查找错误。我使用的跟踪,发现该变量。我在网上搜索找出如何解决我的问题,我想我需要使用if语句,以便确保该计划与变量运行。我想我应该检查鳞片变量,如果是,宣布某种价值了。

I will include the code, but before I do, I need to say that I checked the box to permit debugging in the publish settings, and I do not have a line number to locate the error. I used trace and found out that the null variable is flake. I searched the internet to figure out how to fix my problem, and I think I need to use an if statement so make sure that the program runs with a null variable. I think I should check if the flake variable is null and if it is, declare some kind of value to it.

的问题是,我不知道如何code,如果声明...

The problem is that I do know how to code that if statement...

下面是我的$ C $下accueil_fla,第1帧(可以在那里找到此FLA的所有动作)

Here is my code for accueil_fla, frame 1 (where all the actions for this fla can be found)

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));

我也可以包括code的主页来解决,为什么雪粒子效果不会在第一负荷工作。

I can also include the code for the main page to fix why the snow particle effect does not work on the first load.

//----------------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;
}

再次感谢您的帮助,这是很AP preciated。

Thanks again for your help it is much appreciated.

推荐答案

您的错误是最有可能不是真的在code,但在你的项目设置:你似乎引用一个影片剪辑不是在舞台上当时你调用它。

Your error is most probably not really in your code, but in your project setup: You seem to reference a movie clip that is not on the stage at the time you're calling it.

您必须考虑你的时间表作为一个实际的时间表:本帧重新present时间!如果您的按钮操作触发功能在另一个影片剪辑,它必须是在舞台上在​​该确切时刻的 - 这是不够的,其显示在后面的帧(或在另一个场景,等等)。

You have to think of your timeline as an actual timeline: The frames represent time! If your button action triggers functions in another movie clip, it has to be on the stage at that exact moment - it is not enough to have it appear in a later frame (or in another scene, etc.etc.).

您应该包含null检查的程序,是的,但它如预期反正很可能是行不通的,即使它可能不再崩溃 - 在这里没有什么可以执行的命令,就没有机制来真正做工作...

You should include null checks in your program, yes, but it probably would not work as expected anyway, even though it might no longer crash - where there is nothing that could execute a command, there will be no mechanism to actually do the job...

另外,一旦空对象引用错误被抛出(或去未捕获的,对于这个问题的任何其他错误),你应该不再使用你的程序 - 它坏了,你需要解决它,然后才能继续!你肯定后,第一个不能信任任何错误消息。

Also, once a null object reference error has been thrown (or any other error that went uncaught, for that matter), you should no longer use your program - it is broken, you need to fix it, before you can continue! And you certainly cannot trust any error messages after the first one.

认为它就像上了发条:如果在任何一点上嵌齿轮之一停止了转动,没有任何其他车轮可以 - 但只有其中的一个将被打破,从而导致所有的人发生故障也是如此。你解决第一个错误后,才可以确保有确实是一个问题。

Think of it like a clockwork: If at any point one of the cogwheels stopped turning, none of the other wheels could - but only one of them would be broken, causing all the others to malfunction as well. Only after you fix the first error, you can be sure that there really is another problem.

这篇关于错误#1009,ActionScript 3的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆