Enjoy the component architecture of ActionScript 3.
All visible visual components in ActionScript 3 are unified in displayobject, that is, instances of its subclass. Displayobject is an abstract class and cannot generate instances. From the perspective of system architecture design, this kind of super-class design is common sense. Displayobject, as I mentioned in as3.0 tutorial (5): powerful event mechanism (1), inheriting from the eventdispatcher class means that all displayobject subclasses can send events.
Aha, the abstraction at the lower layer of displayobject is wonderful. The architect's original intention is to divide all the visual components into two categories: accepting Man-Machine Interaction Events and not accepting Man-Machine Interaction Events. Therefore, there are interactiveobject and non-interactiveobject classes. Since the classes of non-interactiveobject are too different and cannot be abstracted in common, they are simply divided into six siblings of interactiveobject, avm1movie, bitmap, and morphshape,Shape, Statictext, video. But he believes that starting from the elegance of the system, he may wish to set up an uninteractiveobject superclass and put the six children under this superclass. It also facilitates future function expansion.
Before talking about the most important interactiveobject, we should first drop these brothers. In these sub-classes, we divide them into code creation and code exposure. The so-called code creation is not allowed. It can only be created using flash creation tools. As before, statictext cannot be implemented using code. The other is morphshape, which is created in flash.ShapeDuring deformation, the Flash Player automatically generates the file. Similarly, the Code cannot be implemented.
The remaining parts can be created using code: bitmap, bitmap object, which can be created through bitmapdata object or loaded from outside, for example through loader.Shape, Shape, used to draw a vector graph, created through a graphic object. Video, a video object, used to play a video. It can be from a file or network streaming media.
The following describes avm1movie, a so-called avm1movie, that is, the SWF film supported by ActionScript Virtual Machine 1, that is, the films of ActionScript 1 and 2. Because ActionScript 3 uses avm2, it cannot communicate with avm1 films across scripts. Therefore, it must be distinguished from avm2 SWF films, so there is a class. For this, I am interested in reading this article: I am talking about the SWF compatibility between ActionScript 3.0 and as 2.0 and 1.0. In general, we do not need to care about this, nor directly engage with it. Once we load an avm1 old film to avm2 SWF, flash player will automatically create an avm1movie instance to wrap this SWF. We often deal with container components that load avm1 SWF.
The next layer of interactiveobject has three classes.
The abstract concept at this layer should be liked again. The architecture designer uses the concept of containers and non-containers to distinguish between visual components. A container can load other displayobject subclass objects. Of course, it also includes its uncles, that is, the classes of non-interactiveobject. The so-called non-container, that is, other displayobjects cannot be added to its view. "Container", this public nature is too important, so it is very clever to abstract it at this layer.
Let's talk about the two non-container classes: textfield and simplebutton. Textfield is basically a dynamic text box that we are familiar. For example, simplebutton is the same name as simplebutton we met in ActionScript 2, but the two are actually quite different. In essence, simplebutton is an important and commonly used UI control in ActionScript 3. It is proposed as a class separately, rather than being ambiguous with movieclip. Everyone knows that in ActionScript 2 and 1, as long as you modify the labels of the first few frames of movieclip, The movieclip will become the same as the button. The use of simplebutton is very simple and practical, which will be detailed later. What I want to emphasize here is that the button and movieclip are not a property. AlthoughSpriteSimilar to its subclass, you can also use buttonmode to perform behavior similar to butoon, but the principle is different.
The rest is the displayobjectcontainer class. You can add other displayobject subclass objects to all the subclass objects of displayobjectcontainer. Note that displayobjectcontainer is an abstract class and cannot generate instances. This is because of the robustness and scalability of the architecture design. It is the same as designing displayobject as an abstract class.
It is important to look at its sub-classes,Sprite, Loader, stage. Stage is the stage. All the visual components are in it and deserve to be the final container. It is reasonable to put them on this layer. Loader is interesting. It abstracts and separates all the previously loaded movieclip parts. All and external resources are loaded through loader. Loader cannot directly deal with network resources. It should be carried out through specialized URLRequest objects and perform their respective duties very well. What can loader do? Load SWF and various images. Note that the video still needs to be carried out through the video class, directly addchild to various iner, not necessarily in loader.
Below comesSprite, We have dealt with the most containers in this 3.0. In a word, it removes the movieclip of the timeline (that is, the movieclip is destroyed ). As I mentioned in the example at the beginning, if we only want to create a containerSpriteIs the first choice. We can even say that more than 90% of our code-writing developers only needSpriteDeal. Movieclip with timeline is generally created by Flash tools and can be loaded only. To be accurate,SpriteThere is more than one timeline less than movieclip in ActionScript 2, such as loading.SpriteIt also contains graphic objects, which means that it can also be directly drawn in the code. But we always need to remember,SpriteDifferent fromShape,DifferencesLies inSpriteIs a container, andShapeNo. From the code point of view, that is,SpriteYou can addchild (),ShapeNo.
It's all about here. Our dear movieclip is still missing. Where is it? In factSprite.SpriteIn the next layer, there are four sub-classes, one of which is movieclip. As you can think of, today's movieclip is not as important as it was before. It mainly represents a video created with a timeline in flash. Common attributes such as gotoandstop and currentframe can be met now.
The other three sub-classes are not small, but the best ones are flexsprite. Although its changes only change the tostring () function, it is the common cornerstone of all flex components. The famous dad of uicomponent is now. Who is uicomponent? All components are output by it. Black Yu boldly predicted that the control we used in Flash 9 is the component in flex, that is, all the components in MX. controls. This class cannot be underestimated.
The other two subclasses preloader and downloadprogressbar are no longer in flash. the display package is MX. the preloaders package mainly manages the download progress and shared library download functions.
At this point, the main visual component architecture of ActionScript 3 has come up with a clear explanation of the context, design reasons, reasons, and ideas. I hope everyone will like it. In fact, textfield and simplebutton of the other two branches under interactiveobject also have a very important position, which will be detailed in subsequent tutorials.
Now it's time for the old bird to share with them my experiences in analyzing the visual architecture of ActionScript 3. It can be seen that the abstract boundary is very clear, and the application mode is also unified. The application mode is one of the most common modes in OOP programming: composite mode. For exampleShapeGraphic object,SpriteThe following soundtransform object, loaderinfo object under loader, and so on. I was confused why I didn't need to use the decorator mode to make the behavior of these components more similar to that of ActionScript 2, but the transition was less painful, but I thought about the painstaking efforts of the Architecture designer. It is necessary to use composite, which is clear and clear, to enhance the collaboration between all developers at Ood time, so as to quickly familiarize themselves with and use the new powerful architecture. Compared with this advantage, what is the pain of such a transition?
The subsequent sections and specific programming examples of Visual Programming in ActionScript 3 will be released one after another.
P.s: This tutorial is protected by the Creative Commons license. Protocol and cannot be used for commercial purposes without the consent of the author.