action script3.0中文版

439
ActionScript ActionScript ActionScript 3.0 3.0 3.0 CookBook CookBook CookBook 中文翻译 作者:Joey Joey Joey Lott, Lott, Lott, DarronSchall, DarronSchall, DarronSchall, Keith Keith Keith Peters Peters Peters 译者:常青( 李新业) 电子邮件:[email protected] [email protected] [email protected] 博客:http://blog.csdn.net/lixinye0123 http://blog.csdn.net/lixinye0123 http://blog.csdn.net/lixinye0123 论坛:http://groups.google.com/group/AS3_CN http://groups.google.com/group/AS3_CN http://groups.google.com/group/AS3_CN 注:因本人水平有限,出现理解错误或翻译不妥之处在所难免,恳请读者批评指正,在阅 读中如遇到不解的问题,可到http://groups.google.com/group/AS3_CN http://groups.google.com/group/AS3_CN http://groups.google.com/group/AS3_CN 留言。 推荐官方阅读器Adobe Reader 8 感谢 www.linuxfans.org www.linuxfans.org www.linuxfans.org 提供下载支持!

Upload: coollen

Post on 26-Jan-2015

163 views

Category:

Education


2 download

DESCRIPTION

 

TRANSCRIPT

  • 1. ActionScript 3.0 CookBookJoey Lott, DarronSchall, Keith Peters Joey()() [email protected] [email protected]://blog.csdn.net/lixinye0123http://blog.csdn.net/lixinye0123 http://groups.google.com/group/AS3_CNhttp://groups.google.com/group/AS3_CNhttp://groups.google.com/group/AS3_CN http://groups.google.com/group/AS3_CN http://groups.google.com/group/AS3_CN Adobe Reader 8 www.linuxfans.org

2. 1.0. ActionScript 3.0 Cookbook 1.0Ajax WPF Macromedia FlashRIAWebRich Internet Application Adobe FlashWebActionScript300 Flash 23 01 ye in ix/l Flash Remoting and web services et .n XML dncs /b g.:/ lotp ht 3. 1.1. ActionScript Flex Builder 2 ActionScript ActionScript ActionScript classSWFHTMLbinFlex Builder 2 File ->New->ActionScript Project, New ActionScript Project New ActionScript Project ExampleApplication .as 2301 bin yeFinish in ixFlex Builder 2 Navigator ExampleApplication /lbinExampleApplication.as et .nOutline import dncs/b g.:/ lo.swf html tp ht Flash IDE .fla , 4. 1.2. SWFclass metadata FlashActionScript 3.0 eclipseActionScript 500x375 .swf, 24/ActionScriptProperties ActionScript Compiler"Additional compiler arguments." 23-default-size width height01ye-default-background-color color-default-frame-rate fpsin ix/let-default-size 800 600 .n-default-background-color 0xffffff dncs-default-frame-rate 31/b g.swf800x600 . :/ lo31tp ht -default-size 800 600 -default-frame-rate 31metadata Metadata [SWF(width="800", height="600", backgroundColor="#ffffff", frameRate="31")]importpackage ...{import flash.display.Sprite;[SWF(width="800", height="600", backgroundColor="#ffffff", frameRate="31")]public class ExampleApplication extends Sprite{public function ExampleApplication(){}}} 5. 1.3. ActionScript ActionScriptActionScript ActionScript ActionScript 1.0 2.0, includeasclass ActionScript 3.0 ActionScript 23 package ...{ 01ye import flash.display.Sprite;in ix /l public class ExampleApplication extends Spriteet ...{ .ndnpublic function ExampleApplication( ) cs ...{ /b g. :/ lo tp } ht } } ActionScript 2.0, 3.0 package Packages ActionScript 2.0, ActionScript 3.0 utilitypackage com.as3cb.utils {} import import import com.as3cb.utils.StringUtils; 6. StringUtils flash.display Sprite Sprite ExampleApplicationclass public swf Flash package ...{import flash.display.Sprite;public class ExampleApplication extends Sprite ...{ public function ExampleApplication( ) ...{graphics.lineStyle(1, 0, 1);for(var i:int=0;i 5);// : false= trace(5 = 5); // : true 15. ActionScript ActionScript (string, number, and Boolean) (object, sprite, and array) quantity total 6var quantity:Number = 6;var total:Number = 6;trace (quantity == total); // : true// var arrayOne:Array = new Array("a", "b", "c");var arrayTwo:Array = new Array("a", "b", "c");trace(arrayOne == arrayTwo); // : false 23object, array, sprite . 01ye// in ixvar arrayOne:Array = new Array("a", "b", "c"); /let// .n dnvar arrayTwo:Array = arrayOne; cstrace(arrayOne == arrayTwo); // : true /b g. :/ lo tp ht 16. 1.9. if switch ActionScript if, switch, (? :).ifswitch if if if 2301 animalName "turtle."yeif (animalName == "turtle") { // trace( ) in ix/ltrace("Yay! Turtle is the correct answer.");et.n} dn else trace() cs /b g.debugshowMessage( ) :/ lo tp ht if (animalName == "turtle") { // showMessage("Yay! Turtle is the correct answer.");}else { // showMessage("Sorry, you got the question wrong.");}else if if else if else if if (animalName == "turtle") {// showMessage ("Yay! Turtle is the correct answer.");}else if (animalName == "dove") { //animalName == "dove"showMessage ("Sorry, a dove is a bird, not a reptile.");} 17. else if switch switch if statements are more legible and succinct than thecomparable if statement. if switch switch switch switch switch casesdefault Case case switch case.Case y23 01caseswitchdefault yeswitch (testExpression) { inix /lcase caseExpression: et.n// case body dncase caseExpression: cs /b g.// case body :/ lo tp default: ht // case body}var animalName:String = "dove";switch (animalName) {case "turtle":trace("Yay! Turtle is the correct answer.");case "dove":trace("Sorry, a dove is a bird, not a reptile.");default:trace("Sorry, try again.");} 18. case break switch var animalName:String = "dove";// 2caseswitch (animalName) {case "turtle":trace("Yay! Turtle is the correct answer.");break;case "dove":trace("Sorry, a dove is a bird, not a reptile.");break;default:trace("Sorry, try again.");23} 01 yeinixswitch (animalName) { /l etcase "turtle":.ncase "alligator": dn cscase "iguana": /b g. :/ lotrace("Yay! You named a reptile."); tp ht break; case "dove":case "pigeon":case "cardinal":trace("Sorry, you specified a bird, not a reptile.");break;default:trace("Sorry, try again.");}ActionScript (? :), 3 varName = (conditional expression) ? valueIfTrue : valueIfFalse; 19. 1.10. AND (&&), OR (||), NOT (!) ActionScript if, while, for , AND , &&, (14)// 317var current:Date = new Date( );if (current.getDate( ) == 17 && current.getMonth( ) == 3) { 23trace ("Happy Birthday, Bruce!"); 01ye}in ix /l et// Check if today is April 17th..n dnif ((current.getDate( ) == 17) && (current.getMonth( ) == 3)) { cstrace ("Happy Birthday, Bruce!"); /b g. :/ lo} tp ht OR , ||, // if ((current.getDay( ) == 0) || (current.getDay( ) == 6) ) {trace ("Why are you working on a weekend?");} NOT, !, // Bruce.if (!(userName == "Bruce")) {trace ("This application knows only Bruces birthday.");}if (userName != "Bruce") { 20. trace ("This application knows only Bruces birthday.");}// sprite if (_sprite.visible) {trace("The sprite is visible.");}NOT false// sprite if (!_sprite.visible) {trace("The sprite is invisible. Set it to visible before trying this action.");} 23NOT OR 01 ye// Bruce Joey.in ixif (!((userName == "Bruce") || (userName == "Joey"))) {/l ettrace ("Sorry, but only Bruce and Joey have access to this application.");.n} dncs/b g.:/ lotp ht 21. 1.11. for for (var i:int = 0; i < 10; i++) {// i.TRace(i);} while for 23for for 01 ye inix/lfor (initialization; test; update) { et .nstatement bodydncs}/b g.:/ lo0999tp ht for (var i:int = 0; i < 1000; i++) {trace(i);}trace ("Thats the end.");var i1j1ijfor (var i:int = 0, j:int = 10; i < 10; i++, j--) {trace("i is " + i);trace("j is " + j);}for for (var i:int = 1; i