intTypePromotion=1
zunia.vn Tuyển sinh 2024 dành cho Gen-Z zunia.vn zunia.vn
ADSENSE

adobe flash cs5 on demand part 60

Chia sẻ: Mr Yukogaru | Ngày: | Loại File: PDF | Số trang:8

62
lượt xem
8
download
 
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Sử dụng ActionScript 3.0 ActionScript 3.0 đã trải qua những thay đổi đáng kể. Điều này không có nghĩa là nếu bạn đã làm việc với Flash ActionScript 1.0 hoặc 2.0 là bạn sẽ hoàn toàn bị mất, nhưng nó sẽ yêu cầu bạn tìm hiểu cách thức mới để sử dụng mã của bạn.

Chủ đề:
Lưu

Nội dung Text: adobe flash cs5 on demand part 60

  1. Using ActionScript 3.0 ActionScript 3.0 has undergone significant There are a score of smaller changes. As changes. This does not mean that if you have you dive directly into ActionScript 3.0 you will worked with Flash ActionScript 1.0 or 2.0 that find a learning curve as you move from you will be completely lost, but it will require ActionScript 2.0. Is it all worthwhile to go that you learn new ways to use your code. through the pain? Absolutely. ActionScript 3.0 is simply so much faster and more powerful Understanding ActionScript 3.0 that it is worth the undertaking. ActionScript 3.0 is a robust programming model (completely up-to-date with the latest Working with ActionScript 3.0 release of the ECMAScript standard) familiar There are two ways in which you can work to developers with a basic knowledge of with ActionScript. The first method is to add object-oriented programming. If you have ActionScript to the Timeline. This will be famil- developed for other programming languages, iar to earlier Flash developers. A good prac- such as Java, C++ or C#, then you have heard tice to get into is to have a layer in that of this term. Object-oriented programming Timeline that is dedicated to just working with allows you break your code into objects that ActionScript. Adobe recommends that you can be easily re-used. With object-oriented label the ActionScript label “Actions. Locking ” programming, it’s easier to manage an appli- the “Actions” layer will prevent you from acci- cation that has a collection of smaller files dentally adding movie clips into it. than one large file. The second method is to insert There are number of changes that will take ActionScript into Flash files with a Class file. a while to get used. The main changes are: Class files have a long history in the develop- ment world. With a Class file you can now ◆ ActionScript is located in Class files or in the Timeline. specify both Public and Private Classes. Using the Private keyword restricts the use of the ◆ Code design is truly object oriented. attribute defined in just that class and not ◆ You cannot add ActionScript directly to shared with other classes. This is useful as movie clips or buttons instances. you develop instruction that needs to be exe- ◆ Triggering events has changed. cuted privately in a closed environment. ◆ Loading data has changed. Other major changes include: ◆ XML is managed differently. ◆ Developing Solutions Built with the DOM3 event model. Some other enhancements include more run-time exceptions for common error condi- ◆ Using Namespaces in your projects. tions, added use of run-time type information, ◆ Controlling Data. improved use of properties and classes with ◆ Controlling Text. sealed classes, added use of method closures for event handling, added use of industry ◆ Drawing with the Shape Class. standard ECMAScript for XML, more support ◆ Ability to easily work with external for regular expressions, and added primitive ActionScript Libraries. types (int and uint). 366 Chapter 15
  2. ActionScript 2.0 and 3.0 Similarities Extending ActionScript with Open With all of the changes between ActionScript Source Libraries 3.0 and 2.0 it’s important to remember that The core to ActionScript 3.0 is that it can be there is a lot of functionality that is the same easily extended. To this end, you can use between them. For instance you still use the dozens of great Open Source Libraries that following in the same way: can be used to extend the functionality of ◆ Variables Flash. Great examples are: ◆ Math object ◆ Box2D Physics Engine (http://box2dflash.sourceforge.net/). ◆ If/Else Statements ◆ Switch Statements ◆ CoreLib (http://code.google.com/p/as3corelib/) a ◆ String collection of basic utilities such as MD5 ◆ Date to control the use of date and time hashing, JSON serialization and advanced data parsing. ◆ Array to build a structured collection of data ◆ Syndication Library ◆ Boolean to specify a true or false (http://code.google.com/p/as3syndication lib/) a library that allows you to parse all The following works in ActionScript 2.0 ATOM and RSS feeds easily. and ActionScript 3.0: ◆ AlivePDF var str:String = new String("Hello, "); (http://www.fpdf.org/) a library that allows you to convert your Flash screen var str2:String = new String("World"); content to PDF. trace (str + str2); These are some of the best Libraries you can use. Each comes with its own level of You can see that the overall syntax struc- documentation. ture is the same between both versions of ActionScript. You still end your code with curly brackets, your variable names are still Extending ActionScript with C/C++ case sensitive, your variable names cannot ActionScript can be extended using C/C++. start with a number and you still use number The Open Source project Brajeshwar.com class objects the same way. (http://brajeshwar.com/2008/cc-to-action- script-compiler/) is a project that allows you For specific details about using an to take C++ programs and compile them to ActionScript language, click the Help menu, run in Flash. As an Example, they were able click Flash Help, and then look in the to take the C++ version of Quake, convert it Programming ActionScript 2.0 or 3.0 or the and run it in Flash. That is darn impressive ActionScript 2.0 or 3.0 Language and and could not be done with ActionScript 2.0. Components Reference online chapter. Chapter 15 Working with ActionScript 3.0 367
  3. Changing ActionScript To take advantage of the new powerful AVM 2.0 and ActionScript 3.0 you must be publishing your Flash movies to target Flash Player 9 or 3.0 Settings later. Adobe has done a great job of ensuring that the latest release of the Flash Player is installed on your computer. For instance, with the release of Flash Player 9, Adobe installed a feature that automatically updates your Player on your PC, Mac users receive updates through the Mac OS update tool and—as part of Flash Player 10.1—will now receive automatic updates as soon as new releases are available. Flash Player 10.1 will help your Flash movies to play back more efficiently on Mac based computers, especially for mobile devices, such as an Android, Palm Pre or BlackBerry phones. Flash Player 10.1 dramatically optimized code for the Cocoa Framework, it uses Apple’s Core Animation to render animation). Mobile users simply have not been able to view Flash. Now they can. To change which Flash Player you are targeting you need to open the Publish Settings and modify the Flash Player settings. Change Publishing Setting for ActionScript 3.0 2 5 3 4 1 Click File, and then click Publish Settings. The default settings on the Formats tab include Flash and HTML. 2 Click the Flash tab. 3 Click the Player list arrow, and then click Flash Player 9 or Flash Player 10. 4 Click the Script list arrow, and then click ActionScript 3.0. 5 Click the HTML tab. 6 To publish settings for a specific subversion (an update to a main release) of the selected Flash Player, select the Detect Flash Version check box, and then enter the Flash Player subversion you want. For example, 10.1.52. This uses SWObject2 for version detection and embedding SWF into Web pages. (New!) 7 Click OK. You are ready to start developing a 7 ActionScript 3.0 Flash movie that uses AVM 2.0. 368 Chapter 15
  4. Change ActionScript 3.0 Settings 2 1 Click File, and then click ActionScript Settings. 2 To create a document class, enter the filename of the ActionScript file without the .as extension. 3 3 Specify the frame where the class definition resides. 4 4 Specify any of the following options: ◆ Strict Mode. Select to to report compiler warnings as errors. ◆ Warnings Mode. Select to report warnings for issues when updating ActionScript 2.0 to ActionScript 3.0. 5 ◆ Automatically declare state instances. Select to automatically declare instances on the Stage. ◆ Dialect. Select ECMAScript or ActionScript 3.0 (Recommended). 5 Click any of the following tabs: ◆ Source path. Specify the location of the external 6 ActionScript files that contain the class definition. ◆ Library path. Specify the location of pre-compiled ActionScript code, which resides in the SWC files. ◆ Config constants. Specify any configuration constants for use with conditional compilation. 6 Click OK. See Also See “Creating a New Document” on page 12 for more information on creat- ing an ActionScript 3.0 FLA document. Chapter 15 Working with ActionScript 3.0 369
  5. Inserting Code with Code hints makes it easy to insert and edit code accurately. With Code hints, you don’t have to remember all of the objects, methods, and prop- Code Hints erties used in ActionScript. As you enter to type code, you can display the Code Hints popup menu to help you enter it correctly (New!). Code hints can appear after the dot (.) following a statement or command, where a property or method needs to appear next, or between paren- theses [()] in a method name. The Code Hints popup menu displays appropriate code options based on the currently entered code. When you enter code that refers to a custom ActionScript 3.0 class, you can also display the Code Hints popup menu to help you access the appro- priate code options (New!). When you use a custom class in a script, Flash automatically imports the related code for its use. Code hinting also works for nested class references, and all classes included in a SWC file. Use Code Hints 2 4 3 5 1 Create or open a Flash document. 2 Open the Actions panel or Script window. 3 Place the insertion point where you want to add code. 4 Start to type the code you want, and then press Control+Spacebar (Win) or A+Spacebar (Mac) or click the Show Code Hint button on the toolbar to manually display the code hints popup menu. 5 Scroll through the list by using the scroll bar or pressing the Up Arrow and Down Arrow keys. 6 6 To insert a code hint, double-click an item, or select it and then press Enter (Win) or Return (Mac). ◆ Press Esc to dismiss the list of code hints. See Also See “Setting ActionScript Preferences” on page 349 for information on enabling code hinting. 370 Chapter 15
  6. Use Code Hints for Custom 2 4 3 Classes 1 Create or open a Flash or class document (ActionScript 3.0). ◆ Store the custom classes in the same folder as the document. 2 Open the Actions panel or Script window. 3 Place the insertion point where you want to add code. 4 Start to type the code you want, and then press Control+Spacebar (Win) or A+Spacebar (Mac) or click the Show Code Hint button on the toolbar to manually display the code hints popup menu. 6 5 5 Scroll through the list by using the scroll bar or pressing the Up Arrow and Down Arrow keys. 6 To insert a code hint, double-click an item, or select it and then press Code Hinting for Custom Classes Enter (Win) or Return (Mac). Properties Options ◆ Press Esc to dismiss the list of code hints. Type this Code hints for that same class Type new+ Displays a list of available classes and packages Did You Know? Type import+ Displays a list of all the built-in packages You can reload code hints without and custom packages restarting Flash. Open the Actions panel, click the Options menu, and then click Reload Code Hints. You can save time with Auto close- bracket insertion. When you type an open bracket { in the Actions panel or Script window, Flash automatically adds the corresponding close bracket }. (New!) Chapter 15 Working with ActionScript 3.0 371
  7. Inserting and Creating As you build Flash documents for ActionScript 3.0, it's almost a certainty that you will use elements over and over again. Flash created a solution Code Snippets that makes it easier to reuse elements called Code Snippets (New!). Snippets offer a simple and convenient method of creating reusable code, which especially helpful for those transitioning from ActionScript 2.0 to ActionScript 3.0. They are composed of bits of code and/or content along with comments for usage that you can save, edit, use, and reuse as often as you want. You can use a pre-defined code snippet supplied by Flash or create your own in the Code Snippets panel (New!). Insert a Code Snippet 1 5 2 4 1 Select the object or Timeline frame in the Flash document where you want to insert/apply the code snippet. 2 Open the Code Snippets panel. 3 Click the arrow icon next to the folder (Actions, Timeline Navigation, Animation, Load and Unload, Audio and Video and Event Handlers) to display the snippet you want to insert. 4 Select the snippet you want to insert. 5 Click the Add to current frame button in the Code Snippets panel. TIMESAVER You can also drag a snippet from the Code Snippets panel directly onto an element, or double-click the code snippet in New layer with ActionScript 3 the Code Snippets panel. In the Actions panel, you can click the Code Snippets button. 6 Click Yes to convert your selection to a movie clip, if necessary. A new ActionScript is added to a new layer, labeled Actions, in the Timeline. Click to Play/Stop Sound snippet code 372 Chapter 15
  8. Create a Code Snippet 1 2 1 Open the Code Snippets panel. 2 Click the Options button in the Code Snippets panel, and then click Create New Code Snippet. 3 Type a title and tooltip. 4 Type the code you want to use in the Code box or click Auto-fill to insert the code selected in the Actions panel. 5 Select or clear the Automatically replace instance_name_here when applying code snippet check box. 6 Click OK. 3 4 Did You Know? You can edit an existing code snippet. In the Code Snippets panel, select the snippet you want to edit, click the Options button, click Edit Code Snippets XML, make the changes you want, click the File menu, click Save, and then click the Close button in the Code Snippets tab. 5 6 You can copy a code snippet to the clipboard. In the Code Snippets panel, select the snippet you want to copy, click the Copy to Clipboard button, and then click OK, if necessary. Now, you For Your Information can paste it into the Actions panel or ActionScript file. Importing and Exporting Code Snippets If you want to share code snippets with others, you can import or export one or more from the Code Snippets panel. To import a code snippet, click the Options button in the Code Snippets panel, click Import Code Snippets XML, select the XML file, and then click Open. To export a code snippet, select the snippet you want to export in the Code Snippets panel, click the Options button, click Export Code Snippets XML, type a name, specify a location, and then click Save. Chapter 15 Working with ActionScript 3.0 373
ADSENSE

CÓ THỂ BẠN MUỐN DOWNLOAD

 

Đồng bộ tài khoản
2=>2