[AS2] Dynamic Creating V2Component

xiaoxiao2021-03-06  17

Can V2Component create a dynamic creation? The answer is obvious. Since V2COMPONET inherits from UIObject, UIObject is inherited from MovieClip, and the properties and methods owned in MovieClip are the same as in V2Component. It is natural to use AttachMovie to dynamically load V2Component. But don't end, isn't it? , The strongest listener in V2Componet has not been used yet. What should you do?

SomeComponent.adDeventListener ("Eventname", ListenObj); listenObj.EventName = function (): void {// ....

It looks good, if these code is written in the main scene with the course of dicing, the problem is not too big. But when the volume is bigger, you should manage it, you will be trouble, you will say, I will make one Specially managed the Component class to create, registered listeners and destroyed work all incorporated, and it is a good idea. If you have only one scene, that is, V2Component is only once in the entire program, there is no problem. But when your program needs to change the corresponding components of different components, things are troublesome, and you will have a huge, and you can reduce it. The lowest. In fact, it is simple to handle, it is divided into and cured, and it creates the effect when it appears.

I now create a sub-package of the home class, called COM, and the specific implementation is placed in another sub-package specially stored, called MSG. So, you can imagine that it is like this: COM --- COMSCENE COMEFFECT1 COMEFFECT2 ... MSG --- Msgscene Msgeffect1 Msgeffect2 ... This seems to be more convenient to make great achievements in the modification and expansion of the entire program.

The specific implementation code is extracted as follows: Class SDGP.SEffect.cs2ball1d {public function cseffectball1d {public function cs2ballinterverse () // Create its own Commag object {mCommag = new cscom2ballconserve (); in his parent class The statement is: private var mCommag: iscommag; // where iscommag is interface class for all COMMAG classes. ...} ..... // Create a component. Public function init (): void {... thisp.mcommag .CREATE (); ...}}

// direct management component class: class Sdgp.SCom.CSCom2BallConserve extends RCSComMag {public function CSCom2BallConserve () {mMsgF = new CSMsg2BallConserve (); // declare its parent class object class: private var mMsgF: ISMsgF; abstract interface point PUBLIC FUNCTION CREATE (): Void {..... _Root.attachmovie ("textinput", "txtm1", 14); _root.txtm1.move (20,200); _root.txtm1.restrict = "^ az ^ az" _Root.txtm1._width = 50; _Root.attachmovie ("TextInput", "TXTM2", 15); _root.txtm2.move (20, 260); _root.txtm2.restrict = "^ az ^ az"; _root.txtm2. _width = 50; .... listeneradd (); // listener registration} public function remove (): void {... EVAL ("_ root.txtm" 1) .removemovieclip (); eval ("_ robot.txtm " 2) .removemovieclip (); ...} private function listeneradd (): void {_root [" txtm " 1] .addeventListener (" Enter ", mmsgf) ;;} .....} // Component's message processing commissioned to MSG class processing: class sdgp.smsg.csmsgsce extends rcsmsgf {public function csmsgsce () {enter = msgenter;

Private function msgenter () {if (evt.target == _ root.txtm1) {// proccess}}

I wrote the code into a stepped shape to show this idea of ​​the graded commissioned. This is the biggest advantage of constructing a program structure is to debug and expand convenient, true.

By the way, I almost forgot, there are a lot of people will ask, the components have the necessary dynamic creation, my answer is yes, at least in the case of frequent updates according to different situations, this is more It is important. Because we hope to use the code to control the program, not too much about this kind of thing. Ready to say that Visual Basic is not? Harmon ~~~~

My way is definitely wrong, and the level of a time is definitely unfained, and I still hope that the high-end pointing is one or two.

转载请注明原文地址:https://www.9cbs.com/read-41749.html

New Post(0)