首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >As3闪存错误“无法访问空对象引用的属性或方法”

As3闪存错误“无法访问空对象引用的属性或方法”
EN

Stack Overflow用户
提问于 2013-04-16 10:07:47
回答 1查看 30K关注 0票数 1

我正试着在flash上做一些随机数的基本游戏,但每次我运行我的场景时都会收到这个错误:

代码语言:javascript
复制
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上:

代码语言:javascript
复制
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 --------

我希望有人能帮我解决这个问题!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-28 15:52:47

错误1009告诉你它不能引用按钮,电影剪辑,文本字段等。一个简单的答案是确保你的按钮有实例名称。我想您使用的是CS6或更老版本的闪存。在这种情况下,选择一个按钮,例如当您在舞台上时选择numerico_btn。然后转到属性面板,在实例输入字段中输入numerico_btn的名称。

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

var numerico_btn:SimpleButton;

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

希望这对你和任何遇到这个最常见的问题的人都有帮助。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16027616

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档