Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 动作脚本3:添加gotoAndStop动画_Actionscript 3_Flash_Class_Animation - Fatal编程技术网

Actionscript 3 动作脚本3:添加gotoAndStop动画

Actionscript 3 动作脚本3:添加gotoAndStop动画,actionscript-3,flash,class,animation,Actionscript 3,Flash,Class,Animation,所以前几天我找到了一个关于如何在动作脚本中创建模式锁定屏幕的教程。为了做到这一点,我必须创建一个类,我很好地掌握了类是如何工作的。但是我想添加一个动画,这样当用户浏览模式中的点并播放动画时。但是我不知道如何在课堂上做这样的事情。这是我在课堂上使用的代码 package { import flash.display.Sprite; import flash.events.MouseEvent; import fl.transitions.Tween; import

所以前几天我找到了一个关于如何在动作脚本中创建模式锁定屏幕的教程。为了做到这一点,我必须创建一个类,我很好地掌握了类是如何工作的。但是我想添加一个动画,这样当用户浏览模式中的点并播放动画时。但是我不知道如何在课堂上做这样的事情。这是我在课堂上使用的代码

package
{
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import fl.transitions.Tween;
    import fl.transitions.easing.Strong;

    public class Main extends Sprite
    {
        private var dots:Array = []; // Stores the in stage movieclips
        private var pattern:Array = []; //The pattern entered by the user
        private var pass:Array = [1,4,7,8,5,2,5]; //The correct pattern to proceed

        public function Main():void
        {
            dots = [one,two,three,four,five,six,seven,eight,nine]; //add the clips in stage
            addListeners();
        }

        private function addListeners():void //adds the listeners to each dot
        {
            var dotsLength:int = dots.length;

            for (var i:int = 0; i < dotsLength; i++)
            {
                dots[i].addEventListener(MouseEvent.MOUSE_DOWN, initiatePattern);
                dots[i].addEventListener(MouseEvent.MOUSE_UP, stopPattern);
            }
        }

        /* Adds a mouse over listener and uses it to add the number of the dot to the pattern */

        private function initiatePattern(e:MouseEvent):void
        {
            var dotsLength:int = dots.length;

            for (var i:int = 0; i < dotsLength; i++)
            {
                dots[i].addEventListener(MouseEvent.MOUSE_OVER, addPattern);
            }

            pattern.push(dots.indexOf(e.target) + 1); //adds the array index number of the clip plus one, because arrays are 0 based
        }

        private function addPattern(e:MouseEvent):void
        {
            pattern.push(dots.indexOf(e.target) + 1); //adds the pattern on mouse over
        }

        private function stopPattern(e:MouseEvent):void //stops storing the pattern on mouse up
        {
            var dotsLength:int = dots.length;

            for (var i:int = 0; i < dotsLength; i++)
            {
                dots[i].removeEventListener(MouseEvent.MOUSE_OVER, addPattern);
            }

            checkPattern();
        }

        private function checkPattern():void //compares the patterns
        {
            var pLength:int = pass.length;
            var correct:int = 0;

            for (var i:int = 0; i < pLength; i++) //compares each number entered in the user array to the pass array
            {
                if (pass[i] == pattern[i])
                {
                    correct++;
                }
            }

            if (correct == pLength) //if the arrays match
            {
              //Hides Sign In
              MovieClip(root).LockScreen.visible = false;
              MovieClip(root).RTID.visible = false;
              MovieClip(root).SignIn.visible = false;
              //Turns On Main Menu
              MovieClip(root).gamemenu_mc.visible = true;
              MovieClip(root).biggamesmenu_mc.visible = true;
              MovieClip(root).totaltextmenu_mc.visible = true;
              MovieClip(root).tmenu_mc.visible = true;
              MovieClip(root).smenu_mc.visible = true;
              MovieClip(root).optionsmenu_mc.visible = true;
            }

            pattern = []; //clears the user array
        }
    }
}

我认为最简单的方法是:

在dot电影剪辑中,在第一帧上放置一个停止动作

在点时间线上创建动画,并在动画的最后一帧上再次停止

在鼠标悬停功能中,告诉圆点播放

private function addPattern(e:MouseEvent):void
{
    var dot:MovieClip = MovieClip(e.currentTarget);
    if(dot.currentFrame < 2) dot.play(); //play only if on the first frame

    pattern.push(dots.indexOf(dot) + 1); //adds the pattern on mouse over
}
重置点动画

 private function stopPattern(e:MouseEvent):void //stops storing the pattern on mouse up
 {
    for (var i:int = 0; i < dots.length; i++)
    {
        dots[i].removeEventListener(MouseEvent.MOUSE_OVER, addPattern);
        dots[i].gotoAndStop(1); //go back to the first frame
    }

    checkPattern();
 }
或者,若你们只是想要一些简单的东西,比如一层淡入/淡出的圆点或者圆点的大小增加,你们可以使用一个tweening库,在鼠标上选择合适的属性tween

如果要绘制线来连接点,可以执行以下操作:

package
{
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import fl.transitions.Tween;
    import fl.transitions.easing.Strong;
    import flash.display.Shape;

    public class Main extends Sprite
    {

        private var lineContainer:Shape = new Shape();

        private var dots:Array = []; // Stores the in stage movieclips
        private var pattern:Array = []; //The pattern entered by the user //don't make life hard, just store the object itself instead of the index
        private var pass:Array;

        public function Main():void
        {
            dots = [one,two,three,four,five,six,seven,eight,nine]; //add the clips in stage
            pass = [one,four,seven,eight,five,two,five]; //The correct pattern to proceed
            addChildAt(lineContainer, this.getChildIndex(one)); //the line container right behind the first dot.
            addListeners();
        }

        private function addListeners():void //adds the listeners to each dot
        {
            var dotsLength:int = dots.length;

            for (var i:int = 0; i < dotsLength; i++)
            {
                dots[i].addEventListener(MouseEvent.MOUSE_DOWN, initiatePattern);
                dots[i].addEventListener(MouseEvent.MOUSE_UP, stopPattern); //you could attach this to `this` instead of each dot, same result
            }
        }

        /* Adds a mouse over listener and uses it to add the number of the dot to the pattern */

        private function initiatePattern(e:MouseEvent):void
        {
            pattern = []; //reset array
            lineContainer.graphics.clear(); //clear lines

            for (var i:int = 0; i < dots.length; i++)
            {
                dots[i].addEventListener(MouseEvent.MOUSE_OVER, addPattern);
            }

                    addPattern(e); //trigger the mouse over for this element
        }

        private function addPattern(e:MouseEvent):void
        {
            //if (pattern.indexOf(e.currentTarget) == -1) { //wrap in this if statemnt if only wanted a dot to be selected once (like Android)
                pattern.push(e.currentTarget); //adds the pattern on mouse over
                drawLines();

                var dot:MovieClip = MovieClip(e.currentTarget);
                if(dot.currentFrame < 2) dot.play(); //play only if on the first frame
            //}
        }

        private function drawLines():void {
            lineContainer.graphics.clear(); //clear the current lines
            lineContainer.graphics.lineStyle(5, 0xFF0000); //thickness (5px) and color (red) of the lines

             if (pattern.length > 1) { //don't draw if there aren't at least two dots in the pattern
             lineContainer.graphics.moveTo(pattern[0].x + pattern[0].width * .5, pattern[0].y + pattern[0].height * .5); //move to first
         for (var i:int = 1; i < pattern.length; i++) {
        lineContainer.graphics.lineTo(pattern[i].x + pattern[i].width * .5, pattern[i].y + pattern[i].height * .5); //draw a line to the current dot
    }
          }

              lineContainer.graphics.endFill();

        }

        private function stopPattern(e:MouseEvent):void //stops storing the pattern on mouse up
        {
            for (var i:int = 0; i < dots.length; i++)
            {
                dots[i].removeEventListener(MouseEvent.MOUSE_OVER, addPattern);
                dots[i].gotoAndStop(1); //go back to the first frame
            }

            checkPattern();
        }

        private function checkPattern():void //compares the patterns
        {
            var pLength:int = pass.length;
            var correct:int = 0;

            for (var i:int = 0; i < pLength; i++) //compares each number entered in the user array to the pass array
            {
                if (pass[i] == pattern[i])
                {
                    correct++;
                }
            }

            if (correct == pLength) //if the arrays match
            {
              //Hides Sign In
              MovieClip(root).LockScreen.visible = false;
              MovieClip(root).RTID.visible = false;
              MovieClip(root).SignIn.visible = false;
              //Turns On Main Menu
              MovieClip(root).gamemenu_mc.visible = true;
              MovieClip(root).biggamesmenu_mc.visible = true;
              MovieClip(root).totaltextmenu_mc.visible = true;
              MovieClip(root).tmenu_mc.visible = true;
              MovieClip(root).smenu_mc.visible = true;
              MovieClip(root).optionsmenu_mc.visible = true;
            }

            pattern = []; //clears the user array
            lineContainer.graphics.clear(); //clear the lines

        }
    }
}

你是什么意思?鼠标悬停?我指的是当用户将鼠标拖动到下一个点上时。单击鼠标,然后在图案上拖动。所以我想在你每次拖动一个点时播放一个动画你想在每个点上播放一个鼠标动画吗?像点变色之类的?或者,您希望播放相同的动画而不考虑特定的点?相同的动画而不考虑经过的点。不管是对是错,你不需要一个类文件来做这件事,把这段代码放在时间线的第一个框架上,删除任何私有/公共语句都会得到同样的结果。嘿,谢谢你的帮助,我想试试这行代码,看看它看起来怎么样,但我正在运行这个错误。找不到类型或类型不是编译时常量:Point。我找到了库的导入。但是线条不会显示是的,我看到我的线条画有一些错误我刚失去记忆,我会做一个真实的例子并更新。我为线条添加了一个容器,因为图形对象绘制在同一父对象中所有其他对象的下方。这可能就是你没有看到他们的原因。这假设其中一层是所有点的最后面一层。我认为私有范围的lineContainer变量应该在类中声明;在没有输入/确认错误的情况下,不想编辑它。