Display hierarchy and code structure that should be used in flash game development

Source: Internet
Author: User

Actionscript2.0AndActionscript3.0There is a big difference,3.0It is a real object-oriented language, and the built-in class structure system should be more reasonable and easy to understand. At the same time, the introduction of display programming and simple and clear display hierarchies are even moreActionScriptA sublimation, Will2.0To a certain extent, the practice is not recommended.

Let's talk about it today.FlashThree levels andCodeComparison of writing (whether it is2.0Or3.0).

 

First: Place all video clips to the main timeline frame in sequence of the game process, and put most of the Code into the script of video editing or button. If this is a movie, my score is★☆☆☆☆.

type 2 : In the game, each component is in the order from the outside to the inside: scenario [ document [ game [ components in the game ] , and the code is put in the first frame of the action layer of the main timeline.

Explain the scenario That is, the stage, where only one video clip is placed, that is, the document is likeActionscript3.0In the file class, the file contains video clips in the game, such as the display of the life value, and a video clip called the game, in the game, "something you can play" is put in the video clip of the game.RPGIn the game, if we want to control map movement, we only need to control the video clip movement of this game and the reverse movement of the main character. The code is put in the first frame.FlashThe best practice recommended in help, but it is often necessary to execute some code at the end of a video clip. For example, to stop playing this video clip, you need to consider another method. There are three methods,1Put a small amount of such code in the last frame of the video clip. At this time, it can still ensure that most of the code is in the first frame of the main timeline;2Calculates the total playback time of the video clip in milliseconds.SetTimeoutMethod to execute the code after playback;3.InEnterframeEvent to determine whether the current frame is the last frame to execute the code after playback.

In this way, my recommendation index is★★★★☆

Third: Fully adopts the object-oriented programming method, the hierarchical structure of video editing (inAs3In the second method, the hierarchical structure is used. However, video clips that require code control in the game or video clips that frequently change when the game is opened are not fixed, instead of putting it on the stageAsAutomatically generated, and all the code is put into an external file. You can even do the following:As2Only one empty video clip named "document" is put on the stage (that is, there is nothing in the video clip), it is bound to an external class,ProgramThe execution starts from the constructor of this class, which is more like application development;As3No Display object is put, and only an external class name is written to thisFlashThe document class box of the attribute. The more "absolute" approach is likeFlashdevelopAll code is external,FlashdevelopGeneratedSWFAfter the file is exported using the decompilation tool, it is found that there is nothing in the stage, timeline, or database. Only the document class box of the attribute has a class name defined previously.

In this way, my recommendation index is★★★★★

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.