Differences
This shows you the differences between two versions of the page.
— | appwiki:flash [2021/08/28 08:27] (current) – created ying | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Flash - Action Script ====== | ||
+ | |||
+ | ===== Basic syntax ===== | ||
+ | |||
+ | <code actionscript> | ||
+ | //variable | ||
+ | var varName: | ||
+ | // type: Number, Interger, Boolean | ||
+ | | ||
+ | //function | ||
+ | function funName(): | ||
+ | |||
+ | //as3 only:events | ||
+ | objName.addEventListener(MouseEvent.CLICK, | ||
+ | function funName(event: | ||
+ | // event type: keyboard event | ||
+ | |||
+ | // classes | ||
+ | package { | ||
+ | import flash.display.MovieClip | ||
+ | public class MyClass extends MovieClip | ||
+ | { | ||
+ | public function MyClass() {} | ||
+ | } | ||
+ | } | ||
+ | // conditional statements | ||
+ | if (condition) { } else { } | ||
+ | // loops | ||
+ | for (var i: | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===== Programming structure with ActionScript ===== | ||
+ | - (main stage) frame-label based state switch screen linear structure | ||
+ | *hard to manage large amount of status | ||
+ | *<code actionscript> | ||
+ | - (button click) movieclip attaching structure | ||
+ | * <code actionscript> | ||
+ | // | ||
+ | - form based screen non-linear structure | ||
+ | * only exists in Flash MX 2004, Flash 8, CS3 and CS4, CS5 has dropped it | ||
+ | |||
+ | ===== Programming with interaction and game like feedback ===== | ||
+ | |||
+ | * hit test <code actionscript> | ||
+ | * mouse hit test< | ||
+ | my_mc.hitTest(_root._xmouse, | ||
+ | // as 3 | ||
+ | my_mc.hitTest(mouseX, | ||
+ | </ | ||
+ | * drag and drop example | ||
+ | * as3: http:// | ||
+ | ====== Element Scripting ====== | ||
+ | ===== button ===== | ||
+ | <code actionscript>// | ||
+ | box_mc.onRollOver = function(): | ||
+ | { box_mc.gotoAndStop(2); | ||
+ | |||
+ | box_mc.onRollOut = function(): | ||
+ | { box_mc.gotoAndStop(1); | ||
+ | |||
+ | box_mc.onPress = function(): | ||
+ | { trace(" | ||
+ | |||
+ | box_mc.onRelease = function(): | ||
+ | { trace(" | ||
+ | |||
+ | // actionscript 3.0 | ||
+ | box_mc.addEventListener(MouseEvent.MOUSE_OVER, | ||
+ | box_mc.addEventListener(MouseEvent.MOUSE_OUT, | ||
+ | box_mc.addEventListener(MouseEvent.MOUSE_DOWN, | ||
+ | box_mc.addEventListener(MouseEvent.CLICK, | ||
+ | |||
+ | box_mc.buttonMode = true; // enables use of hand cursor | ||
+ | |||
+ | function mouseOverHandler($e: | ||
+ | { box_mc.gotoAndStop(2); | ||
+ | |||
+ | function mouseOutHandler($e: | ||
+ | { box_mc.gotoAndStop(1); | ||
+ | |||
+ | function mouseDownHandler($e: | ||
+ | { trace(" | ||
+ | |||
+ | function mouseClickHandler($e: | ||
+ | { trace(" | ||
+ | </ | ||
+ | |||
+ | ===== component flvplayer ===== | ||
+ | <code actionscript>// | ||
+ | // as2 | ||
+ | flv_view.contentPath = " | ||
+ | |||
+ | // as3 | ||
+ | flv_view.source = " | ||
+ | </ | ||
+ | ===== Drawing element ===== | ||
+ | |||
+ | * draw a dynamic line with action script 2 (ref: [[http:// | ||
+ | // AS2 | ||
+ | this.createEmptyMovieClip(" | ||
+ | function drawLine(){ | ||
+ | line_mc.clear(); | ||
+ | line_mc.lineStyle(5, | ||
+ | line_mc.moveTo(0, | ||
+ | line_mc.lineTo(100, | ||
+ | line_mc._x = 80; | ||
+ | line_mc._y = 60; | ||
+ | updateAfterEvent(); | ||
+ | } | ||
+ | this.onMouseMove = function(){ | ||
+ | drawLine(); | ||
+ | } | ||
+ | </ | ||
+ | * action script 3 version (ref: [[http:// | ||
+ | var line_mc: | ||
+ | this.addChild(line_mc); | ||
+ | function drawline(){ | ||
+ | line_mc.graphics.clear(); | ||
+ | line_mc.graphics.lineStyle(5, | ||
+ | line_mc.graphics.moveTo(0, | ||
+ | line_mc.graphics.lineTo(100, | ||
+ | line_mc.x = 80; | ||
+ | line_mc.y = 60; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | * more reference on AS 2.0 vs AS 3.0 on MovieClip creation: | ||
+ | * http:// | ||
+ | * draw line and curve | ||
+ | * http:// | ||
+ | * draw shape | ||
+ | * http:// | ||
+ | * simple drawing app | ||
+ | * http:// | ||
+ | ===== actionscript 2 ===== | ||
+ | ==== external script loader ==== | ||
+ | <code actionscript> | ||
+ | #include " | ||
+ | </ | ||
+ | |||
+ | ==== XML loader ==== | ||
+ | <code actionscript> | ||
+ | var myXML:XML = new XML(); | ||
+ | myXML.ignoreWhite = true; | ||
+ | myXML.onLoad = function (success: | ||
+ | var colors:XML = this.firstChild; | ||
+ | for (x=0; | ||
+ | var node: | ||
+ | yourActionFun({label: | ||
+ | } | ||
+ | } | ||
+ | myXML.load(" | ||
+ | </ | ||
+ | ==== text field ==== | ||
+ | <code actionscript> | ||
+ | // ActionScript 2.0 | ||
+ | createTextField(" | ||
+ | theTextField.type = " | ||
+ | theTextField.border = true; | ||
+ | theTextField.multiline = true; | ||
+ | theTextField.wordWrap = true; | ||
+ | </ | ||
+ | |||
+ | ===== actionscript 3 ===== | ||
+ | ==== difference in ActionScript 3 ==== | ||
+ | * object oriented design structure applied | ||
+ | * based on that structure, ActionScript no longer can be stored on object, it must be in main timeline | ||
+ | * centralized coding | ||
+ | |||
+ | ==== external as loader ==== | ||
+ | <code actionscript> | ||
+ | include " | ||
+ | </ | ||
+ | ==== xml loader ==== | ||
+ | <code actionscript> | ||
+ | var myLoader: | ||
+ | myLoader.load(new URLRequest(" | ||
+ | </ | ||
+ | |||
+ | ==== FLV loader ==== | ||
+ | |||
+ | <code actionscript> | ||
+ | // load flv function | ||
+ | |||
+ | </ | ||
+ | ==== text field ==== | ||
+ | <code actionscript> | ||
+ | // ActionScript 3.0 | ||
+ | var theTextField: | ||
+ | theTextField.type = TextFieldType.INPUT; | ||
+ | theTextField.border = true; | ||
+ | theTextField.x = 10; | ||
+ | theTextField.y = 10; | ||
+ | theTextField.multiline = true; | ||
+ | theTextField.wordWrap = true; | ||
+ | addChild(theTextField); | ||
+ | </ | ||
+ | |||
+ | ==== image loader ==== | ||
+ | <code actionscript> | ||
+ | var myholder=new Loader(); | ||
+ | myholder.load(newURLRequest(" | ||
+ | |||
+ | //add to stage at position | ||
+ | myholder.x=20; | ||
+ | myholder.y=20; | ||
+ | myholder.name=" | ||
+ | addChild(myholder); | ||
+ | |||
+ | //change holder content | ||
+ | myholder=new Loader(); | ||
+ | myholder.load(newURLRequest(" | ||
+ | |||
+ | //update | ||
+ | myholder.x=30; | ||
+ | myholder.y=30; | ||
+ | addChild(myholder); | ||
+ | </ | ||
+ | |||
+ | ==== movieclip control ==== | ||
+ | |||
+ | * play/stop nested movieclip: http:// | ||
+ | |||
+ | ==== fk/ik animation control ==== | ||
+ | |||
+ | * IK in flash: http:// | ||
+ | |||
+ | ====== Common js_fl_script for flash UI interaction ====== | ||
+ | Common config: | ||
+ | * shortcut < | ||
+ | * workspace < | ||
+ | * swf < | ||
+ | * cmd < | ||
+ | |||
+ | ===== get js_fl interaction script from history panel ===== | ||
+ | |||
+ | Display the commands | ||
+ | - open " | ||
+ | - right on panel > view > " | ||
+ | - note: what you see in history panel is what the command drives | ||
+ | |||
+ | Execute the commands | ||
+ | - copy the command to a text file, save as " | ||
+ | - go to Command menu > Run command ... (load that file) to run | ||
+ | |||
+ | ===== jsfl script ===== | ||
+ | |||
+ | * ASnow.jsfl <code javascript>// | ||
+ | // First Frame Now | ||
+ | // | ||
+ | // Shining Camera January: | ||
+ | // | ||
+ | // get my first frame, so i can directly go to script it | ||
+ | |||
+ | var tl = fl.getDocumentDOM().getTimeline(); | ||
+ | var frameArray = tl.layers[0].frames; | ||
+ | var n = frameArray.length; | ||
+ | |||
+ | // go back to first frame | ||
+ | fl.getDocumentDOM().getTimeline().currentFrame = 0; | ||
+ | fl.getDocumentDOM().getTimeline().currentLayer = 0;</ | ||
+ | |||
+ | ===== SWF UI created in Flash for Flash ===== | ||
+ | * Flash Mac location: < | ||
+ | * Flash win location: < | ||
+ | %usserprofile%\AppData\Local\Adobe\Flash CS3\en\Configuration\WindowSWF</ | ||
+ | |||
+ | reference: http:// | ||
+ | |||
+ | ===== jsfl api reference ===== | ||
+ | |||
+ | * flash cs3 jsfl api pdf: http:// | ||
+ | * jsfl intro: http:// | ||
+ | |||
+ | ====== Flash - Online Application Development ====== | ||
+ | ===== embed flash in html ====== | ||
+ | <code html> | ||
+ | <object width=" | ||
+ | <param name=" | ||
+ | <embed src=" | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ===== XML server communication ===== | ||
+ | |||
+ | Flash -> data.xml -> PHP <PROCESS XML> PHP -> data.xml -> Flash | ||
+ | |||
+ | * post var method <code actionscript>// | ||
+ | var xmlResponse: | ||
+ | var xmlListener: | ||
+ | xmlResponse.addListener(xmlListener); | ||
+ | xmlListener.onLoad = registrationResponse; | ||
+ | |||
+ | submit_btn.onRelease = function(): | ||
+ | var userNameVal: | ||
+ | var emailVal: | ||
+ | var passwordVal: | ||
+ | |||
+ | xmlResponse.sendAndLoad(" | ||
+ | } | ||
+ | |||
+ | function registrationResponse(success){ | ||
+ | if (success) { | ||
+ | // do something wtih the XML | ||
+ | }else{ | ||
+ | trace(" | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | <?php | ||
+ | $username = $_GET[' | ||
+ | $email = $_GET[' | ||
+ | $password = $_GET[' | ||
+ | |||
+ | //now do something with those values | ||
+ | $someValue = "some value here"; | ||
+ | // and echo out some XML that you want flash to deal with | ||
+ | |||
+ | echo "< | ||
+ | echo "< | ||
+ | echo "</ | ||
+ | ?> | ||
+ | </ | ||
+ | * post XML method <code actionscript>// | ||
+ | // flash xml holder | ||
+ | var myXML:XML = new XML(); | ||
+ | myXML.ignoreWhite= true; | ||
+ | myXML.onLoad = function(success){ | ||
+ | if(success){ | ||
+ | trace(this); | ||
+ | } | ||
+ | } else{} | ||
+ | } | ||
+ | // xml info trigger and picker | ||
+ | var msgXML:XML = new XML("< | ||
+ | msgXML.sendAndLoad(" | ||
+ | </ | ||
+ | <?php | ||
+ | // flash xml msg picker | ||
+ | $raw_data = file_get_contents(" | ||
+ | // process xml msg | ||
+ | $xml = new SimpleXMLElement($raw_data); | ||
+ | $data=$xml-> | ||
+ | // print $data; // got the table name | ||
+ | |||
+ | // | ||
+ | if($data == " | ||
+ | print "<? | ||
+ | } | ||
+ | else{ | ||
+ | print "<? | ||
+ | } | ||
+ | ?> | ||
+ | </ | ||
+ | |||
+ | ===== flash data driven app structure ===== | ||
+ | |||
+ | * Data structure | ||
+ | * xml connector | ||
+ | * data set | ||
+ | * data grid | ||
+ | * Data binding | ||
+ | * connection between data sources (in Component Inspector panel) | ||
+ | |||
+ | * Flash app example, | ||
+ | * dynamic charts in Flash: http:// | ||
+ | ====== Flex - development environment ====== | ||
+ | |||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | |||
+ | |||
+ | ====== Flash Open Component ====== | ||
+ | |||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | |||
+ | ====== Best Flash Game I like ====== | ||
+ | |||
+ | * Canabalt (single): http:// | ||
+ | * RoboKill (single): http:// | ||
+ | * BoxHead 2 Play (2 player): http:// | ||
+ | * Bubble Tanks 2: http:// | ||
+ | |||
+ | ====== Flash Developer Blogs ====== | ||
+ | |||
+ | * Valentin Simonov' | ||
+ | * Summit Projects Flash Blog (Code and Projects): http:// | ||