Actionscript 3 在as3中,如何在移动到下一帧之前删除一个tween

Actionscript 3 在as3中,如何在移动到下一帧之前删除一个tween,actionscript-3,Actionscript 3,我有一部旋转的电影。当用户拖放它以停止旋转并处于初始位置时,我需要它。我写了这段代码,但得到了错误类型error:error#1009:无法访问null对象引用的属性或方法。 当我移动到下一帧时,在omoixes10_fla::MainTimeline/EntFrame()处。我看不出我做错了什么。你能帮我查一下密码吗?在我移动到下一帧之前,我必须移除吐温吗 import flash.display.MovieClip; import fl.transitions.Tween; import f

我有一部旋转的电影。当用户拖放它以停止旋转并处于初始位置时,我需要它。我写了这段代码,但得到了错误类型error:error#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);
      }
 }
}

因此,第一个问题是在enter框架内添加事件侦听器,这不是正确的方法,因为它将继续在每个框架中添加事件侦听器

第二,您应该使用我之前推荐的鼠标移动事件侦听器来跟踪和测试命中测试

第三,由于您正在旋转MovieClip,并且希望它返回初始状态,因此您应该执行以下操作:

Piece1_mc.rotation=0;

希望这有帮助。

您正在Enter框架中添加事件侦听器。这将继续在每一帧添加事件侦听器!这永远不会带来好结果:(将拖动事件侦听器移到enter框架外。另一方面,如果您所做的只是添加拖放事件,为什么需要enter框架事件?谢谢,您说得对,但我的代码中肯定有更多错误,因为当我在enter框架内删除事件侦听器时,我的hitTestObject无法工作。添加鼠标移动侦听器当拖动开始时,检查鼠标移动事件侦听器中的点击测试,并完全删除不需要的输入帧。记住在拖动完成时或点击测试成功时删除鼠标移动侦听器。我更正了它。它工作正常。现在唯一的问题是将旋转的movieclip放在初始位置w当用户点击拖动它。你能用最新的代码更新你的问题吗?我会看一下。谢谢。