首先我只做动作脚本2周,并为看起来很多道歉。在时间轴上我有2帧,第一帧只有一个按钮进入下一个屏幕。第二个屏幕有2个按钮,允许前进或后退1帧。
我有一个名为main的类文件,它用于所有动作脚本 该程序工作正常,直到我为2帧上的2个按钮添加事件监听器然后我得到TypeError:
错误#1009:无法访问null对象的属性或方法 。参考\桌面\天气\ Main.as:17]
调试会话终止。
停止功能后直线17
package
{
import flash.display.*;
import flash.events.*;
public class Main extends MovieClip
{
public function Main()
{
// constructor code
Play_btn.addEventListener(MouseEvent.CLICK, playClicked);
stop();
back_btn.stage.addEventListener(MouseEvent.CLICK, backClicked);
forward_btn.stage.addEventListener(MouseEvent.CLICK,forwardClicked);
}
function playClicked(evt:MouseEvent):void
{
nextFrame();
}
function backClicked(evt:MouseEvent):void
{
if (currentFrame == 1)
{
gotoAndStop(totalFrames);
}
else
{
prevFrame();
}
}
function forwardClicked(evt:MouseEvent):void
{
if (currentFrame == totalFrames)
{
gotoAndStop(1);
}
else
{
nextFrame();
}
}
}
}
/*
back_btn.addEventListener(MouseEvent.CLICK, backClicked);
forward_btn.addEventListener(MouseEvent.CLICK, forwardClicked);
stop();
function backClicked(evt:MouseEvent):void
{
if(currentFrame == 1)
{
gotoAndStop(totalFrames);
}
else
{
prevFrame();
}
}
function forwardClicked(evt:MouseEvent):void
{
if(currentFrame == totalFrames)
{
gotoAndStop(1);
}
else
{
nextFrame();
}
}
答案 0 :(得分:0)
尝试一下:
function Main()
{
if(!stage){
addEventListener(flash.events.Event.ADDED_TO_STAGE, onAddedToStage);
}
else{
onAddedToStage(null);
}
}
function onAddedToStage(e:Event):void
{
if(hasEventListener(flash.events.Event.ADDED_TO_STAGE)){
removeEventListener(flash.events.Event.ADDED_TO_STAGE, onAddedToStage);
}
Play_btn.addEventListener(MouseEvent.CLICK, playClicked);
stop();
back_btn.stage.addEventListener(MouseEvent.CLICK, backClicked);
forward_btn.stage.addEventListener(MouseEvent.CLICK,forwardClicked);
}