Actionscript 3 - Session 3 Action Script And Flash

3,415 views

Published on

Actionscript 3 - Session 3 Action Script And Flash
Taught by Oum Saokosal, Head of Information Technology, National Polytechnic Institute of Cambodia

Published in: Technology, Education
1 Comment
3 Likes
Statistics
Notes
No Downloads
Views
Total views
3,415
On SlideShare
0
From Embeds
0
Number of Embeds
23
Actions
Shares
0
Downloads
187
Comments
1
Likes
3
Embeds 0
No embeds

No notes for slide

Actionscript 3 - Session 3 Action Script And Flash

  1. 1. Computer Animation with Flash CS3 & ActionScript 3.0 National Polytechnic Institute of Cambodia Bachelor of IT, Year III, Semester 1 2007-2008 by Oum Saokosal, Head of IT Department
  2. 2. ActionScript and the Flash Authoring Tool (Cont.) Computer Animation with Flash CS3 & ActionScript 3.0
  3. 3. ActionScript and the Flash Authoring Tool (Cont.) <ul><li>Linked Classes for Movie Clip Symbols </li></ul><ul><li>Instantiating Symbols via ActionScript </li></ul><ul><li>The Document Class </li></ul>
  4. 4. Linked Classes for Movie Clip Symbols (1) <ul><li>In ActionScript: </li></ul><ul><li>Almost everything, except graphic, could be a class (including Button, Movie Clip, Sound etc). </li></ul><ul><li>Every instances are objects </li></ul>
  5. 5. Linked Classes for Movie Clip Symbols (2) <ul><li>Q. But how to make the symbols be Classes? </li></ul><ul><li>A. You have to link it. To link it, please </li></ul><ul><ul><li>Click on an existing symbol,e.g. Rectangle in Library </li></ul></ul><ul><ul><li>Right Click -> Linkage </li></ul></ul><ul><ul><li>Then check on “Export for ActionScript” -> OK -> OK </li></ul></ul>
  6. 6. Instantiating Symbols via ActionScript <ul><li>As you know, every symbol can be classes. </li></ul><ul><li>After you created a linked class, you can instantiate by creating object from the class. </li></ul><ul><ul><li>var rec1:mvRectangle = new mvRectangle(); </li></ul></ul><ul><ul><li>rec1.x = 200; </li></ul></ul><ul><ul><li>rec1.y = 50; </li></ul></ul><ul><ul><li>addChild(rec1); //Add an object to stage </li></ul></ul><ul><ul><li>To instantiate(v) : To create instance </li></ul></ul>
  7. 7. Important Codes (1) <ul><li>To create objects: </li></ul><ul><ul><li>var star:mvStar = new mvStar(); // Movie Clip </li></ul></ul><ul><ul><li>var shortgun:ShortGun = new ShortGun(); // Sound </li></ul></ul><ul><li>To add the objects to stage: </li></ul><ul><ul><li>addChild(star); </li></ul></ul><ul><li>To hide/show mouse cursor: </li></ul><ul><ul><li>Mouse.hide(); //To hide </li></ul></ul><ul><ul><li>Mouse.show(); //To show </li></ul></ul><ul><li>To play sound: </li></ul><ul><ul><li>shortgun.play(); </li></ul></ul>
  8. 8. Important Codes (2) <ul><li>To add Event to stage: </li></ul><ul><li>stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDownOnStage); </li></ul><ul><li>Location of Mouse: </li></ul><ul><ul><li>mouseX; </li></ul></ul><ul><ul><li>mouseY; </li></ul></ul>
  9. 9. Lab: CreateStars <ul><li>Create stars in the sky by just clicking. </li></ul>
  10. 10. Lab: ShootingWall <ul><li>Shooting Wall (with Sound) </li></ul>
  11. 11. The Document Class (1) <ul><li>What is the Document Class? </li></ul><ul><li>- The Document Class is a external ActionScript class file (*.as) which is linked to Flash documents (*.fla). </li></ul><ul><li>- It helps to decouple coding from designing. That is, you design animations in Flash (*.fla) whereas you code in another external class file (*.as). </li></ul><ul><li>- It enables you to use OOP features easily. </li></ul><ul><li>- Note that it is available for AS 3.0 only. </li></ul>
  12. 12. The Document Class (2) <ul><li>How to create the Document Class? </li></ul><ul><li>Create a new Flash file (AS3.0). </li></ul><ul><li>Create animations. But you should create button or MovieClip symbols for every part of animations . Then save the file, say, FlashEx.fla. </li></ul><ul><li>Next, create AS file by clicking on File ->New ->ActionScript File. </li></ul><ul><li>Write your codes. Then save it, ASEx.as . </li></ul>
  13. 13. The Document Class (3) <ul><li>Please switch back to FlashEx.fla . </li></ul><ul><li>On the Flash file property, you will see a textbox called “Document Class”. </li></ul><ul><li>Please type your AS file name, “ASEx”. </li></ul>
  14. 14. The Document Class (3) - Sample <ul><li>1. Open AS file: HelloWorld.as </li></ul><ul><ul><li>package { </li></ul></ul><ul><ul><li>import flash.display.Sprite ; </li></ul></ul><ul><ul><li>import flash.events.MouseEvent; </li></ul></ul><ul><ul><li>public class HelloWorld extends Sprite { </li></ul></ul><ul><ul><li>public function HelloWorld() { </li></ul></ul><ul><ul><li>stage. addEventListener ( MouseEvent.MOUSE_DOWN , </li></ul></ul><ul><ul><li>mouseDown); </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><ul><li>private function mouseDown (e: MouseEvent ): void { </li></ul></ul><ul><ul><li>trace (&quot;Hello World&quot;); </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><ul><li>} </li></ul></ul>
  15. 15. The Document Class (3) - Sample <ul><li>Open Flash (AS3.0) file </li></ul><ul><li>On properties panel and in the Document Class, please write HelloWorld </li></ul>
  16. 16. Lab: Exercise <ul><li>To rebuild the exercise CreateStars and ShootingWall by using document class. </li></ul><ul><li>Hint: </li></ul><ul><ul><li>In Flash file, create only symbols and then link them to be classes. </li></ul></ul><ul><ul><li>In AS file, write code. </li></ul></ul>

×