如何在移动到as3中的下一帧之前删除补间

时间:2015-08-18 18:00:19

标签: actionscript-3

我有一个旋转的影片剪辑。当用户将其拖放到停止旋转并处于其初始位置时,我想要它。我写了这段代码,但我得到错误TypeError:错误#1009:无法访问null对象引用的属性或方法。     当我移动到下一帧时,在omoixes10_fla :: MainTimeline / EntFrame()。我看不出我做错了什么。你能帮我解决一下我的代码吗?在移动到下一帧之前,是否必须删除补间?

import flash.display.MovieClip;
import fl.transitions.Tween;
import fl.transitions.easing.*;


tick1.parent.removeChild(tick1);
wrong1.parent.removeChild(wrong1);

sentences2.buttonMode=true;
sentences1.buttonMode=true;
Piece1_mc.buttonMode=true;

var my_x:int=stage.stageWidth
var my_y:int=stage.stageHeight
var myWidth:int=0-my_x;
var myHeight:int=0-my_y;
var boundArea:Rectangle=new Rectangle(my_x, my_y, myWidth ,myHeight);



var spin:Tween=new Tween(Piece1_mc, "rotation",Elastic.easeInOut,0,360,5,true);
    spin.stop();



sentences2.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);

function fl_MouseClickHandler(event:MouseEvent):void
{
    snoopy.gotoAndPlay(2);
    addChild(tick1);
    addChild(wrong1);
    sentences2.removeEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
    sentences1.removeEventListener(MouseEvent.CLICK,  fl_MouseClickHandler_2);
    spin.start(); 
    spin.addEventListener(TweenEvent.MOTION_FINISH, onFinish);
    function onFinish(e:TweenEvent):void {
     e.target.yoyo();

    {
     Piece1_mc.addEventListener(MouseEvent.MOUSE_DOWN, DragP1);
     function DragP1 (event:MouseEvent):void 
    {
        Piece1_mc.startDrag();
        Piece1_mc.startDrag(false,boundArea);
        spin.stop();
    }

    stage.addEventListener(MouseEvent.MOUSE_UP, DropP1);
    function DropP1(event:MouseEvent):void 
    {
        Piece1_mc.stopDrag();
    }
    if(Targ1_mc.hitTestObject(Piece1_mc.Tar1_mc)) {
        Piece1_mc.x=677;
        Piece1_mc.y=48,10;
        myTimer.start();
    spin.stop();
    }
    }
}


sentences1.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_2);

function fl_MouseClickHandler_2(event:MouseEvent):void
{
    snoopy.gotoAndPlay(64);
}


var myTimer:Timer = new Timer(2000,1);
myTimer.addEventListener(TimerEvent.TIMER, timerListener);
function timerListener (e:TimerEvent):void {
gotoAndStop(15);

 if (Piece1_mc.parent)
      {
         Piece1_mc.parent.removeChild(Piece1_mc);
      }if (tick1.parent)
      {
         tick1.parent.removeChild(tick1);
      }
    if (wrong1.parent)
      {
         wrong1.parent.removeChild(wrong1);
      }
 }
}

1 个答案:

答案 0 :(得分:1)

所以第一个问题是在输入框架中添加你的事件监听器,这不是正确的方法,因为它将继续在每一帧添加事件监听器。

其次,您应该使用我之前建议的鼠标移动事件监听器来跟踪和测试您的命中测试。

第三,既然你正在旋转你的MovieClip,并且你希望它回到它的初始状态,你应该这样做:

Piece1_mc.rotation=0;

希望这有帮助。