-->

AS3闪存错误“无法访问空对象引用的属性或方法”(As3 flash error “Cannot a

2019-10-18 01:08发布

我尝试做一对夫妇的上闪光,在由随机数,但即时通讯每次运行我的场景时收到此错误的基本游戏:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at capacitacion_fla::MainTimeline/frame1()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at capacitacion_fla::MainTimeline/frame1()
at flash.display::MovieClip/gotoAndStop()
at capacitacion_fla::MainTimeline/fl_ClickToGoToAndStopAtFrame()

我学习闪存和AS3,我将不胜感激,如果有人可以帮助我知道怎么回事,我也离开你我的AS3代码被全部放置在第1帧:

stop();
import com.greensock.*;
import com.greensock.easing.*;
import flash.events.MouseEvent;
import flash.display.MovieClip;

var blitMask1:BlitMask = new   BlitMask(strip1,strip1.x,strip1.y,strip1.width,207,true,true,0xffffff,true);
var blitMask2:BlitMask = new BlitMask(strip2,strip2.x,strip2.y,strip2.width,207,true,true,0xffffff,true);
// ------- botones ----------

numerico_btn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame);

function fl_ClickToGoToAndStopAtFrame(event:MouseEvent):void
{
gotoAndStop(1);
}

preguntas_btn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_2);

function fl_ClickToGoToAndStopAtFrame_2(event:MouseEvent):void
{
gotoAndStop(2);
}

imagenes_btn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_3);

function fl_ClickToGoToAndStopAtFrame_3(event:MouseEvent):void
{
gotoAndStop(3);
}



//------- Fin de los botones ----------

//------------ Escena 1 ----------------------------------------------------
spin_btn.addEventListener(MouseEvent.CLICK, spin);

function spin(event:MouseEvent):void {

var i:int = 1;
while (i <= 2) {
    var newNumber:Number = (randomNumber(0, 19) * 207) + 4968;

    TweenMax.to(this["strip" +i], 2 + (i*.5), {y:strip1.y + newNumber});
    i++;    
}
}

function randomNumber(min:Number, max:Number):Number {
//good
return Math.floor(Math.random() * (1 + max - min) + min);
}
// ----------- fin escena 1 ----------

// ----------- Principio escena 2 -------------------

var blitMask3:BlitMask = new BlitMask( strip1q, strip1q.x, strip1q.y, 392 , strip1q.height, true, true, 0xffff00, true);


preguntas_btn.addEventListener(MouseEvent.CLICK, rodarPreguntas);

function rodarPreguntas(event:MouseEvent):void {

    preguntas_btn.visible = false;

    var newNumber1:Number = (randomNumber1(0, 50)*392) + 21168 ;
    //tween to the relative value of newNumber
    TweenMax.to(strip1q, 4, {x:String(-newNumber1), onComplete:showBtn});       
}

function showBtn(){
preguntas_btn.visible = true;
}

function randomNumber1(min:Number, max:Number):Number {
//good
return Math.floor(Math.random() * (1 + max - min) + min);
}

// ------- Fin escena 2 --------

我希望有人能帮助我搞清楚了这一点!

Answer 1:

错误1009是告诉你,它不能引用一个按钮,影片剪辑,文本字段等的一个简单的答案,你将确保按钮具有实例名称。 我想,你正在使用CS6或更早版本的Flash。 在这种情况下,选择一个按钮,像numerico_btn当你在舞台上。 然后去属性面板,并在实例中的输入栏填入numerico_btn的名称。

这样做对所有的按钮。 最后,声明这些按钮。 例如:

VAR numerico_btn:SimpleButton的;

这应该解决您的错误。 只是作为一个另外,请确保您的按钮被添加numerico_btn.enabled = true来启用; 之前事件监听器。

希望可以帮助你和其他人谁运行到这个最常见的,一开始的问题。



文章来源: As3 flash error “Cannot access a property or method of a null object reference”