1

我试图在 Flash 上做一些包含随机数的基本游戏,但每次运行我的场景时都会收到此错误:

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

我正在学习 flash 和 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 --------

我希望有人可以帮助我解决这个问题!

4

1 回答 1

3

错误 1009 告诉您它无法引用按钮、影片剪辑、文本字段等。对您来说一个简单的答案是确保您的按钮具有实例名称。我想您正在使用 CS6 或旧版本的 Flash。在这种情况下,选择一个按钮,例如在舞台上时的 numeric_btn。然后转到属性面板并在实例输入字段中输入 numerico_btn 的名称。

对所有按钮执行此操作。最后,声明这些按钮。例如:

var numerico_btn:SimpleButton;

那应该可以解决您的错误。作为补充,通过添加 numeric_btn.enabled = true; 确保您的按钮已启用。在您的事件侦听器之前。

希望对您和遇到这个最常见的初始问题的其他人有所帮助。

于 2013-04-28T07:52:46.643 回答