闪存AS3错误控制来自外部的动作按钮 [英] Flash AS3 Error controlling button from external actionscript

查看:137
本文介绍了闪存AS3错误控制来自外部的动作按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

帮助。基本上,我有2个按钮,在不同的帧。如果第1帧上的按钮,点击后,它会去,并停止在框架2.如果框架2单击按钮,它会去,并停止在第1帧我试图做的是控制这个按钮在外部ActionScript文件。没有问题的第一个按钮运行,而第二人似乎响应不正确,并有此错误信息:

类型错误:错误#1009:无法访问空对象引用的属性或方法。
    在SRC ::主/的init()
    在SRC ::主()

这里的code:

 包SRC
{
进口对象类型:flash.events.Event;
进口flash.events.MouseEvent;
进口的flash.display.MovieClip;

/ **
 * ...
 * @author vimoetz
 * /
公共类主要扩展影片剪辑
{

    公共函数main():无效
    {
        如果(阶段)的init();
        其他的addEventListener(Event.ADDED_TO_STAGE,INIT);
    }

    私有函数初始化(E:事件= NULL):无效
    {
        removeEventListener(Event.ADDED_TO_STAGE,INIT);
        this.gotoAndStop(1);
        button1.addEventListener(MouseEvent.CLICK,gotoFrame2);
        button2.addEventListener(MouseEvent.CLICK,gotoFrame1);
    }

    公共职能gotoFrame2(E:的MouseEvent)
    {
        this.gotoAndStop(2);
    }

    公共职能gotoFrame1(E:的MouseEvent)
    {
        this.gotoAndStop(1);
    }

}

}
 

解决方案

您需要从的init 函数删除此行:

  button2.addEventListener(MouseEvent.CLICK,gotoFrame1);
 

和功能 gotoFrame2 的变化是这样的:

 公共职能gotoFrame2(E:的MouseEvent)
    {
      this.gotoAndStop(2);
      如果(!button2.hasEventListener(MouseEvent.CLICK)){
        button2.addEventListener(MouseEvent.CLICK,gotoFrame1);
      }
    }
 

Help. Basically i have 2 button at different frame. If the button on frame 1 clicked, it will go to and stop at frame 2. If the button on frame 2 clicked, it will go to and stop at frame 1. What I'm trying to do is controlling this button over external actionscript file. The 1st button running with no problem, while the 2nd one seems to not responding properly and have this error message:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at src::Main/init()
    at src::Main()

Here's the code:

package src 
{
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.MovieClip;

/**
 * ...
 * @author vimoetz
 */
public class Main extends MovieClip 
{

    public function Main():void 
    {
        if (stage) init();
        else addEventListener(Event.ADDED_TO_STAGE, init);
    }

    private function init(e:Event = null):void 
    {
        removeEventListener(Event.ADDED_TO_STAGE, init);
        this.gotoAndStop("1");
        button1.addEventListener(MouseEvent.CLICK, gotoFrame2);
        button2.addEventListener(MouseEvent.CLICK, gotoFrame1);
    }

    public function gotoFrame2 (e:MouseEvent)
    {
        this.gotoAndStop("2");
    }

    public function gotoFrame1 (e:MouseEvent)
    {
        this.gotoAndStop("1");
    }

}

}

解决方案

You need to remove this line from your init function:

button2.addEventListener(MouseEvent.CLICK, gotoFrame1);

and the function gotoFrame2 change like this:

public function gotoFrame2 (e:MouseEvent)
    {
      this.gotoAndStop("2");
      if (!button2.hasEventListener(MouseEvent.CLICK)){
        button2.addEventListener(MouseEvent.CLICK, gotoFrame1);
      }
    }

这篇关于闪存AS3错误控制来自外部的动作按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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