重置、补间、AS3

发布于 2024-08-25 22:55:32 字数 2602 浏览 13 评论 0原文

计数后如何重置我的数字?我想要一个类似 onComplete 函数的东西。

描述
我的动画从当前位置前进 120 像素,然后飞离舞台。 它是循环的,在前进之前会溜溜到底部。我不想要我的号码 溜溜球或飞离舞台。我的数字每次计数必须向前移动 120 像素,然后 返回。

替代文本 http://www.ashcraftband.com/myspace/videodnd/tweener___.jpg< /a>

NumbersView.as '代码可以工作,但是按照描述的方式是混乱的'

package   
{ 
    import flash.display.DisplayObject; 
    import flash.display.MovieClip; 
    import flash.utils.Dictionary; 
    import flash.events.Event; 
    import caurina.transitions.Tweener; 

    public class NumbersView extends MovieClip 
    { 
        private var _listItems:Array; 
        private var previousNums:Array; 
        private const numHeight:int = 120; 

        public function NumbersView()  
        { 
            _listItems = new Array(); 
            previousNums = new Array(); 
   //Tweener.init();

            var item:NumberImage; 
            for (var i:Number = 0; i < 9; i++) { 
                item = new NumberImage(); 
                addChild(item); 
                item.x = i * item.width; 
                _listItems.push(item); 
            } 
        } 

        public function setTime($number:String):void { 
            var nums:Array = $number.split(""); 
            //trace("$number = " + $number);
            for (var i:Number = 0; i < nums.length; i++) { 
                if (nums[i] == previousNums[i]) continue; 
                Tweener.removeTweens(_listItems[i]);    

                //newY:int = -numHeight;
    var newY:int = int(nums[i]) * -numHeight;
    trace("newY = " + newY);
                trace("currY = " + _listItems[i].y);

    /*----------------------PROBLEM AREA, RIGHT HERE------------------------*/
                //if (_listItems[i].y < 0) _listItems[i].y = numHeight;//
                //Tweener.addTween(_listItems[i], { y:newY, time:3 } );//
    Tweener.addTween(_listItems[i], { y:_listItems[i].y+newY, time:3 } );//
            } 
            previousNums = nums; 
        } 
    } 
} 

Tweener 示例
http://hosted.zeh.com.br/ tweener/docs/en-us/parameters/onComplete.html

**哎呀!
//垃圾代码是“不要使用它的注释”,而不是针对任何人的代码的评论


文档类
发布设置/Flash/设置“高级 ActionScript 3.0 设置”/文档类:NumbersView

CLASS 符号 70x1080,数字 70x120
库/“右键单击”属性/类:NumberImage

How do I reset my numbers after they count? I want something like an onComplete function.

DESCRIPTION
My animation advances 120 pixels from it's current position, then flys off the stage.
It was looping, and would yoyo to the bottom before advancing. I don't want my numbers
yoyoing or flying off the stage. My numbers must move 120 pixels forward each count, then
return.

alt text http://www.ashcraftband.com/myspace/videodnd/tweener___.jpg

NumbersView.as 'the code works, but in a messed up way as described'

package   
{ 
    import flash.display.DisplayObject; 
    import flash.display.MovieClip; 
    import flash.utils.Dictionary; 
    import flash.events.Event; 
    import caurina.transitions.Tweener; 

    public class NumbersView extends MovieClip 
    { 
        private var _listItems:Array; 
        private var previousNums:Array; 
        private const numHeight:int = 120; 

        public function NumbersView()  
        { 
            _listItems = new Array(); 
            previousNums = new Array(); 
   //Tweener.init();

            var item:NumberImage; 
            for (var i:Number = 0; i < 9; i++) { 
                item = new NumberImage(); 
                addChild(item); 
                item.x = i * item.width; 
                _listItems.push(item); 
            } 
        } 

        public function setTime($number:String):void { 
            var nums:Array = $number.split(""); 
            //trace("$number = " + $number);
            for (var i:Number = 0; i < nums.length; i++) { 
                if (nums[i] == previousNums[i]) continue; 
                Tweener.removeTweens(_listItems[i]);    

                //newY:int = -numHeight;
    var newY:int = int(nums[i]) * -numHeight;
    trace("newY = " + newY);
                trace("currY = " + _listItems[i].y);

    /*----------------------PROBLEM AREA, RIGHT HERE------------------------*/
                //if (_listItems[i].y < 0) _listItems[i].y = numHeight;//
                //Tweener.addTween(_listItems[i], { y:newY, time:3 } );//
    Tweener.addTween(_listItems[i], { y:_listItems[i].y+newY, time:3 } );//
            } 
            previousNums = nums; 
        } 
    } 
} 

Tweener Example
http://hosted.zeh.com.br/tweener/docs/en-us/parameters/onComplete.html

**oopse!
//crap code was' s note not to use it', not a comment against anyone's code


DOCUMENT CLASS
Publish Settings/Flash/Settings 'Advanced ActionScript 3.0 Settings'/Document class:NumbersView

CLASS Symbol 70x1080, numbers 70x120
Library/'right-click' Properties/Class:NumberImage

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

×纯※雪 2024-09-01 22:55:32

我花了一些时间才弄清楚你真正想要得到的最终结果是什么,但我想我已经弄清楚了。我将此功能分为两类。 NumbersView 类仍然是文档类,但我还创建了一个 NumberImage 类,您可以将其附加到库中的 0-9 数字影片剪辑中。代码如下:

//NumbersView.as - Your Document Class
package {

    import flash.display.MovieClip;

    public class NumbersView extends MovieClip {

        private var _listItems:Array; 
        private const numHeight:int = 120; 

        public function NumbersView()  
        { 
            _listItems = new Array();

            var item:NumberImage; 
            for (var i:Number = 0; i < 9; i++) { 
                item = new NumberImage(); 
                addChild(item); 
                item.x = i * item.width; 
                _listItems.push(item); 
            }

            setTime('123456789');

        }

        public function setTime($number:String):void { 
            var nums:Array = $number.split(""); 
            trace(nums);

            for (var i:Number = 0; i < nums.length; i++) { 

                _listItems[i].start( int(nums[i]) );

            } 

        } 


    }
}

下一个类是 NumberImage.as 类,您可以通过右键单击库中的项目“属性...”,选中“导出为 ActionScript”,然后将 NumberImage 添加到您的影片剪辑中,将其连接到该类。类名。

//NumberImage.as - Linked to the NumberImage movieclip in the Library    
package {

    import flash.display.MovieClip;
    import caurina.transitions.Tweener;

    public class NumberImage extends MovieClip {

        public var count:int;

        public function NumberImage() {
            count = 0;
        }

        public function start( num:int = 0 ):void {
            this.y = -120*num;
            count = num;
            moveNumbers();
        }

        public function moveNumbers():void {
            count++;
            if(count % 10 == 0) {
                Tweener.addTween( this, {y: this.y + 1080, time:1, onComplete:moveNumbers});
            } else {
                Tweener.addTween( this, {y: this.y - 120, time:1, onComplete:moveNumbers});
            }
        }

    }
}

希望这更有意义,并且现在更容易破译 NumberImage 对象的功能是由它们自己处理的,而不是由它们的包含类处理的。

It took me a little while to figure out what you're really trying to get as an end result, but I think I figured it out. I split this functionality into 2 classes. The NumbersView class is still the document class, but I also made a NumberImage class that you can attach to your 0-9 numbers movieclip in your library. Here's the code:

//NumbersView.as - Your Document Class
package {

    import flash.display.MovieClip;

    public class NumbersView extends MovieClip {

        private var _listItems:Array; 
        private const numHeight:int = 120; 

        public function NumbersView()  
        { 
            _listItems = new Array();

            var item:NumberImage; 
            for (var i:Number = 0; i < 9; i++) { 
                item = new NumberImage(); 
                addChild(item); 
                item.x = i * item.width; 
                _listItems.push(item); 
            }

            setTime('123456789');

        }

        public function setTime($number:String):void { 
            var nums:Array = $number.split(""); 
            trace(nums);

            for (var i:Number = 0; i < nums.length; i++) { 

                _listItems[i].start( int(nums[i]) );

            } 

        } 


    }
}

The next class is the NumberImage.as class that you can hook up to your movieclip by right-clicking the item in the library, "Properties...", Check "Export for ActionScript", and put in NumberImage for the Class name.

//NumberImage.as - Linked to the NumberImage movieclip in the Library    
package {

    import flash.display.MovieClip;
    import caurina.transitions.Tweener;

    public class NumberImage extends MovieClip {

        public var count:int;

        public function NumberImage() {
            count = 0;
        }

        public function start( num:int = 0 ):void {
            this.y = -120*num;
            count = num;
            moveNumbers();
        }

        public function moveNumbers():void {
            count++;
            if(count % 10 == 0) {
                Tweener.addTween( this, {y: this.y + 1080, time:1, onComplete:moveNumbers});
            } else {
                Tweener.addTween( this, {y: this.y - 120, time:1, onComplete:moveNumbers});
            }
        }

    }
}

Hopefully this makes more sense and it's easier to decipher now that the functionality of the NumberImage objects are handled by themselves rather than by their containing class.

树深时见影 2024-09-01 22:55:32

我能想到的最合乎逻辑的解决方案是扩展包含所有数字的图像,使其两端都有一个 9,即:在 8 之后,图像的顶端有一个 9,但在 0 之前还有一个 9,位于图像的底部。

然后,您只需要进行一些测试即可找出您的图像在其循环的每个点在舞台上的位置。您需要知道在图像的任一端显示任一 9 时它将所处的位置。然后,您只需放入一个 if 语句来测试对象何时到达该位置(这意味着它正在显示最上面的 9),当该值等于 true 时,使图像的位置等于最下面的 9。当您执行此更改时,不要使用 Tweener,因为您希望它向下对齐到一帧中的其他 9 个位置,因此观看者不会意识到它。

希望你能明白我在说什么。你的代码让我感到困惑,所以我不太确定(没有花太多时间试图理解它)你会把这个逻辑放在哪里,但我假设你知道。

The most logical solution I can think of from the top of my head is to extend the image that contains all your numbers so that it has a 9 at each end, i.e.: after the 8 there's a 9 at the top end of the image, but before the 0 there's also a 9, at the bottom of the image.

Then you just need to do some tests to find out what positions on the stage your image will be in at each point of it's cycle. You need to know the position it will be in when displaying either of the 9s, at either end of the image. Then you simply put in an if-statement to test when the object reaches the position which means it's displaying the top-most 9, and when that equals true, make the image's position equal to the bottom-most 9. When you do this change, don't use Tweener, as you want it to snap down to the other 9 position in one frame, so the viewer isn't aware of it.

Hope you see what I'm saying. Your code confuses me, so I'm not really sure (without spending too long trying to understand it) where you'd put this logic in, but I assume you'd know.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文