Placing AS3 code on stage/MC timelines a la AS2 instead of in classes

后端 未结 2 1565
無奈伤痛
無奈伤痛 2021-01-29 14:57

I\'m aware that ActionScript 3.0 is designed from the ground up to be a largely object-oriented language and using it means less or even no timeline code in Flash documents.

2条回答
  •  春和景丽
    2021-01-29 15:23

    From the examples you've given on how you use Flash, nothing has really changed to make any of that more difficult. There is no reason why you should use external code for all the above. You can work pretty much the same as before (gotoAndPlay, gotoAndStop still exist and work just fine). The only thing that comes to mind that is more tedious than it used to be is the fact there is no more getURL(). However, Senocular has remade the getURL class and you can find it here.

    I would say, only if your project is particularly code heavy, then move most if not everything into classes and structure it properly in an OOP manner. Heck, you can even just pass a reference to your stage to a base class and just operate pretty simply in that manner as well.

    In your .fla timeline:

    import com.yourdomain.Main;
    
    var main:Main = new Main(this);
    

    In your external Main Class:

    package com.yourdomain
    {   
        public class Main
        {
            private var mainTimeline:Object;
    
            public function Main(_mainTimeline:Object):void
            {
                mainTimeline = _mainTimeline;
    
                mainTimeline.gotoAndPlay("fScream");
            }
        }
    }
    

提交回复
热议问题