Wiley.Games.on.Symbian.OS.A.Handbook.for.Mobile.Development.Apr.2008 (779888), страница 72
Текст из файла (страница 72)
Figure 11.2 shows a SWF, which is divided into two main parts.First come the library assets, which are the vector, bitmap and sound files.The other half is the compiled bytecode created from any ActionScript.The SWF is compressed, allowing it to be downloaded quickly whenFLASH LITE OVERVIEW325SWFAssetsBytecodeFigure 11.2 The parts of a SWF filethe user purchases a Flash Lite game. SWF files have to be opened withthe Flash Lite player that is built onto the smartphone. Although this isacceptable for testing purposes, it forces the users to first find and openthe Flash Player and then use it to open the SWF file, which becomes abarrier to use.11.3.1 Symbian OS SpecificsA better way to deliver a game to a Symbian smartphone is by using aSIS file.
This file is read by the Symbian software installer that allowsthe secure installation of any game or application. The SIS file containsa certificate guaranteeing the origin of the game, acquired from Symbian Signed, for which you can find more information on the SymbianDeveloper Network at developer.symbian.com. Games provided as SISfiles are visible in the application launcher and are shown with their ownunique icon and name. This way, the user does not need to know whichtechnology was used to create the game. They just have a quick and simple way to install and launch the game and to enjoy it. Packaging up SISfiles requires the SDK for the phone.
Alternatively, there are commercialtools7 available that will take the SWF, an application icon, and create aSIS file.Flash Lite applications are able to launch native applications. Forexample, a game could launch the web browser and have it load thewebsite with more details about the game itself or other games that areavailable. Because Symbian OS is an open platform there are alreadythird-party frameworks8 that allow Flash Lite content to access additionaldevice functionality. This includes phone book, messaging, camera, GPS,and Bluetooth access. Flash Lite can additionally play native content such7SWF2Go is a professional toolkit for Adobe Flash Lite, which allows developers tocreate Symbian SIS installer and SWF launcher icon for Flash Lite applications.
Moreinformation can be found at www.orison.biz/products/swf2go.8A good example is ‘Kuneri Lite’ found at www.kuneri.net or ‘Flyer’ (requires Pythonfor S60) www.flyerframework.org.326FLASH LITE GAMES ON SYMBIAN OSas video files, and it is simple to discover phone specific details such asthe exact screen resolution.11.3.2 ActionScriptActionScript is the scripting language that makes Flash a runtime.
It isbased on the same ECMAScript9 standard as JavaScript. Its syntax is easyto learn, and developers of Java and JavaScript will find it a simplestep to pick up. ActionScript 2.0 is the version used for Flash Lite 2.xdevelopment. Memory management, as with Java, is handled by a garbagecollection mechanism. There is no risk of broken pointers, memory leaks,and data type errors.Unlike Java, ActionScript does not force everything to be written as aclass. For example, ‘Hello World’ in ActionScript is simply:trace("Hello World");A real world example that works outside of a test environment wouldbe:var textBox:TextField; // Declare and type the textbox variable// Add a TextField called textbox to the displaycreateTextField("textBox", 1, 0, 0, 100, 15);textBox.text = "Hello World"; // Set the text to show Hello WorldActionScript is optionally typed.
Typing variables and functions allowsthe compiler to give early warnings of problems. This flexible typing alsoextends to arrays, which can hold any type of object without the need forcasting. Flash Lite has a flexible and forgiving language compiler. Whilegreat for beginners learning to code, this and other features, such as lackof runtime error messages, can make it harder to finalize a Flash Litegame.11.3.3 The Benefits of OOPActionScript 2.0 offers an explicit, but optional object oriented programming (OOP) syntax.
To ensure that a Flash Lite game reaches acommercial standard, some early architectural decisions are needed. Tomanage the code effectively, OOP must be used, and code split intoseparate classes. The benefits of Flash OOP are manifold, for example:• the classes created can be reused• multiple coders can work on the game in parallel9See www.ecma-international.org/publications/standards/Ecma-262.htm.FLASH LITE OVERVIEW327• OOP techniques and knowledge such as design patterns can be used• a range of advanced development tools are available.Stricter and faster compilers, unit test frameworks, and entire ActionScript IDEs are only available for ActionScript that is split into OOPclasses.There is an alternative way of working that is a common Flash development style used by many designers.
Small scripts can be placed ondifferent parts of the timeline and are activated when the play headreaches them (see the MovieClip explanation below). It is possible tocreate an entire game on the timeline with the Flash CS3 Professionalapplication.However, a word of warning: although visually impressive games canbe created in this way, having a large timeline, with assets all over theplace, hundreds of separate frames, and code literally anywhere comes ata cost. Maintenance at the end of the project can be slow and expensive.It is laborious to navigate a project and move hundreds of objects aroundthe timeline, and this approach generally means that only a single personcan work on the game.
It is initially a fast way to create a game but shouldbe limited, in most cases, to only being used for aspects that require aquick prototype.11.3.4 The MovieClip classWithin a game, MovieClip classes are used for animation, sprites, buttons,playing cards, UFOs, and explosions. Each individual MovieClip has itsown timeline and play head. Figure 11.3 shows a MovieClip as well asa few useful properties, methods, and events that the class supports. Thecombination of properties, methods, and events that MovieClip supportsallows an almost unlimited array of options for designing various parts ofthe game.._x, ._y._xscale, ._yscale._rotation._alpha.hitTest().play().onEnterFrame()Figure 11.3A MovieClip and the useful properties, methods and events the class supports328FLASH LITE GAMES ON SYMBIAN OSAs I mentioned, every MovieClip has its own timeline.
The timelineis visualized in the Flash IDE and is similar to a filmstrip with separateframes. A powerful feature of the timeline is that the sound can besynchronized to match up with specific frames of the animation ona timeline. This can be used to enable lip-syncing of characters, orto ensure that the sound of a monster exploding occurs at the sametime as the visuals.
The play head relates to the current frame of theMovieClip that is being played at any given moment. The play head ofany MovieClip can also be programmatically stopped or moved to a newposition.The independent timeline of a MovieClip enables some clever gamefunctionality. The different states of a sprite can be placed on differentframes of a MovieClip. For example frame 1 could have a laser cannon inits normal state, frame 2 could have it firing and frame 3 could have thegraphic of the laser cannon exploding when an alien weapon has hit it.ActionScript can then be used to move the play head to the correct frameto show the correct graphic, or set to play a range of frames that showan animation.
Laser cannons can then explode properly in a shower ofpieces, not go bang in one single frame.Using the Flash CS3 Professional tool, MovieClips can be stored asassets in the SWFs library. Specific ActionScript classes can then belinked to these MovieClips so that, when they are used at run time inthe game, the linked class that controls them is automatically instantiatedas well.11.3.5 Layers and Child MovieClipsOne way of working is to have all MovieClips on independent layers,something that is shown in Figure 11.4.
This way of working may becomeprogressively complex, but great versatility comes from adding childMovieClips to a parent. For example, if we had a MovieClip called‘moonBase,’ we could attach several child clips to it, based on assets inthe SWF’s library.Layer nLayer 2Layer 1Figure 11.4 Independent MovieClip layersFLASH LITE DEVELOPMENT TOOLS329var laserCannonClip:MovieClip;laserCannonClip = moonBase.attachMovie("laserCannonAsset", "laserCannon1",moonBase.getNextHighestDepth());We now have a laser cannon attached to the MovieClip of themoonBase. The enemy hits it with a shrink ray that also makes everything slightly transparent.
In Flash, child MovieClips inherit the propertiesof the parent.moonBase._xscale = 50;moonBase._yscale = 50;moonBase._alpha = 50;This would shrink both the moon base and laser cannon as well asset their alpha transparency to 50 %. This allows sweeping changes to beapplied to many MovieClips quickly and easily with small amounts ofcode. This way of working is useful with masks as all the child MovieClipswill show through the mask that the parent clip is seen through. Thissaves the need for multiple masks to show related content.A powerful demonstration of how ActionScript, MovieClips, and thetimeline events combine is in how easy it is to create movement. Asthe timeline ticks from frame to frame, it generates an event calledonEnterFrame.moonBase.onEnterFrame = function() {this._x++;this._rotation++;}This would send the MovieClip spinning clockwise and travelingrightwards at however many frames per second the Flash game is set to.There are entire books dedicated to ActionScript, some of which areanimation and game specific.
See the links provided in section 11.5 formore information about the multitude of books, videos, and websites thatcan fill in all the details.11.4 Flash Lite Development Tools11.4.1 Flash CS3 ProfessionalFlash CS3 Professional (the CS3 stands for Creative Suite 3) is the maintool for Flash development. Apart from a tool to package the binariesinto a SIS file for installation onto the Symbian smartphone, for example,SWF2Go described in section 11.3.1, everything needed to develop aFlash Lite game is installed along with the Flash CS3 Professional (whichI’ll call simply the ‘Flash IDE’ or ‘CS3’ in the rest of this text). There is330FLASH LITE GAMES ON SYMBIAN OSno need to download and install SDKs or scripting languages, or to setup environment variables. CS3 is available on its own or as part of avariety of suites that include other products in the Creative Suite includingFireworks, Illustrator and Photoshop.CS3 is the first Flash IDE released since Adobe and Macromediamerged.