1 / 35

Flash Action Script for Interactive Games

Learn how to use Action Script in Flash to create interactive games and non-linear presentations. This guide covers animation control, using buttons and movie clips, and implementing conditional statements.

jkaiser
Download Presentation

Flash Action Script for Interactive Games

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. "The games of a people reveal a great deal about them.“ Marshall McLuhan Intro to Action Script

  2. The programming language inside Flash. Allows Flash objects react to events such as the user choices or random events. Controls animation in non-linear presentations, interactive applications and games. Actions scripts are lists of instructions for Flash to follow. Action Script Action Script places in the Flash movie Frames Buttons Movie clips

  3. Window > Actions ( F9 ) Action Script panel

  4. to frames select frame in the timeline then select (type in) function in the Actions panel to buttons select button in the stage then select (type in) function in the Actions panel to movie clips name movie clip in the properties window select movie clip in the stage then select (type in) function in the Actions panel To Apply Scripts

  5. Controlling Flash playback gotoAndPlay(“frame”); command to jump and play specific frame in the movie gotoAndStop (“frame”); command to jump and stop at the specific frame in the movie Frame scripts

  6. Create a new movie with 4 keyframes and name them Animation Aesthetics Concept Fun Frame scripts

  7. Select “Animation” frame and apply script gotoAndPlay (“fun”); Select “fun” frame and apply script gotoAndPlay (“concept”); Select “concept” frame and apply script gotoAndPlay (“aesthetics”); Select “aesthetics” frame and apply script gotoAndPlay (“animation”); Test the movie Control > test movie Frame scripts

  8. Make a new layer “buttons” Create graphics for two buttons on the stage play and stop Select button play and convert it into the button symbol Modify > convert to symbol > button Edit individual button frames in the individual button timelines for rollover and press effects Select play button on the stage and apply the script in the actions window: on (press) { play(); } Button scripts

  9. Select stop button on the stage and apply the script in the actions window: on (press) { stop(); } Test the movie Button scripts

  10. Make a new layer “movie_clips” Create graphics for movie clip character on the stage Select graphics and convert it into the movie clip symbol Modify > convert to symbol > movie clip Drag 2 instances of the movie clip to the stage and name them : char1 and char2 Movie clip scripts

  11. Select char1 on the stage and apply the following script using Actions window Movie Clip Control onClipEvent (enterFrame) { this._x+=5; } this refers to the movie clip itself .dot after the object means you want to access object property _x horizontal position of the object += move object 5 pixels at a time Movie clip scripts

  12. Select char2 on the stage and apply the following script using Actions window Movie Clip Control onClipEvent (enterFrame) { this._x=_root._xmouse; this._y=_root._ymouse; } _root addresses the main timeline _xmouse horizontal position of the mouse cursor on the stage _ymouse vertical position of the mouse cursor on the stage Movie clip scripts

  13. Storage units to store numbers or string of characters allowing dynamic data transactions Must be declared and initialized before use myVar = 5; myVar +=2; myVar2=“hello AD305”; Arithmetic operators: + addition - subtraction / division * multiplication -- decrement ++ increment % modulo (remainder of division) variables

  14. A=7; B=5; C=A+B; trace(C); Math functions built in Flash > Math Math.random() function MyRandNum = int(Math.radom()*10); cerates random number from 0 to 9 D=“hello”; E=“world”; F=D+E; (F=“helloworld”) trace(F); G=D+” “ +E; (G=“hello world”) trace(G); variables

  15. Control structure Sequence structure Loop structure Structured programming

  16. A == B A is equal to B The result is true if the expressions are equal. A != B A is not equal to B Returns true if the operands are not the same. A < B A is less than B Returns true if the left operand is mathematically smaller than the right operand. A > B A is greater than B Returns true if the left operand is mathematically larger than the right operand. Relational operators

  17. A <= B A is less than or equal to B Returns true if the left operand is mathematically smaller than or the same as the right operand. A >= B A is greater than or equal to B Returns true if the left operand is mathematically larger than or the same as the right operand. Relational operators

  18. Conditional statement in its simplest form is specified by keyword IF If (this condition is true) { execute this statement ; } Can contain several statements If (this condition is true) { do this ; and this ; and this ; } If (a == 7) { gotoAndPlay (“special_frame”) ; } Conditional statements

  19. To extend the scope of the IF control statement we can use keyword ELSE If (this condition is true) { execute this statement ; } else { this statement ; } If (a == 7) { gotoAndPlay (“special_frame”) ; } Else { gotoAndPlay (”another_frame”) ; } Conditional statements

  20. If (a == 7) { gotoAndPlay (“special_frame”) ; } Else if (a == 12) { gotoAndPlay (”another_frame”) ; } Else if (a == 15) { gotoAndPlay (”very_special_frame”) ; } Else { gotoAndPlay (”not_so_special_frame”) ; } Conditional statements

  21. If statement is fundamental building block for all programs To change variables Branch to other frames Decisions on the score etc. Conditional statements

  22. Used to combine relational operators compare Boolean values (true and false) and return a third Boolean value and adding two operands produces a true result only when both operands are true or ORing two operands produces a true result is either operand is true && Returns true only if both the left and right operands are true || Returns true if either the left or right operand is true !NOT: Returns the logical (Boolean) opposite of the operand. The logical NOT operator takes one operand. Logical Operators

  23. If ((a == 7) and (b == 12)) { gotoAndPlay (”another_frame”) ; } If ((a == 7) and (username == “alex”)) { gotoAndPlay (”alex_frame”) ; } Logical Operators

  24. A loop is a control structure that allows one or more events to occur as long as a given condition remains true For loop allows automatic incrementation of a variable For (initialization; condition ; increment/decrement) { statement ; } For (i=0 ; i<10 ; i++) { trace (i) ; } Loops

  25. Create an instance of the char3 movie clip on the stage For ( i = 1 ; i <= 8 ; i++ ) { _root . char3 . _x++ ; } Loops

  26. An autonomous module that performs tasks Piece of code that can be reused function sum ( m , o ) { L = m + o ; return L ; } trace ( sum ( 3 , 15 )) ; Functions

  27. Arrays allow to store a sequence of variables of the same type. Fruit = [“apple”, “orange”, “peach”, “plum”] ; 0 1 2 3 myItem = Fruit[1] ; To create an empty array and add items: Fruit = new Array(); Fruit.push(“apple”); Fruit.push(“orange”); Fruit.push(“peach”); Fruit.push(“plum”); Arrays

  28. while ( Fruit . Length > 0 ) { trace ( Fruit . pop ()) ; } .push adds element to array .pop returns element of the array .sort to list array elements in alphabetical or numerical order Fruit . Sort ( ) ; Arrays

  29. Fruit = new Array(); Fruit.push(“apple”); Fruit.push(“orange”); Fruit.push(“peach”); Fruit.push(“plum”); Fruit . Sort ( ) ; trace ( Fruit . toString ( )) ; Arrays

  30. Fruit = [“apple”, “orange”, “peach”, “plum”] ; 0 1 2 3 Fruit . splice (2 , 1 ) ; 2 –element position to start removing (“peach”) 1 – how many elements to remove (1) .splice removes elements from the array Fruit . splice (2 , 1, “pear” ) ; “peach” is removed and “pear” is inserted into that position Arrays

  31. Fading trail of objects behind the mouse cursor Make new movie with movie clip “cursor trail” In the library right mouse button click on the properties of the movie clip and check Linkage export for Action Script Make a dummy movie clip outside of the stage and apply the following action script Mouse trail

  32. onClipEvent(load) { // creates empty array to hold references for the trail movie clips trail = new Array(); trailNum = 0; // variable trailNum keeps track of the number of next movie clip to be created // variable speed is used to determine how fast the trail movie clips shrink and fade speed = 2; } Mouse trail

  33. onClipEvent(enterFrame) { // new trail // creates a new movie clip from the library trailNum // allows any movieclip in the library which has been given a linkage id to be // attached to an existing movieclip (or the main timeline) in the movie // while it is running. // Note that if you attach a movieclip at the same depth as something that // already exists in the timeline at that depth, the previous thing will be deleted. _root.attachMovie("cursor trail","cursor trail"+trailNum,trailNum); “Linckage ID”, “clipname”, depth var mc = _root.attachMovie("cursor trail","cursor trail"+trailNum,trailNum); Mouse trail

  34. // set position to the current cursor position mc._x = _root._xmouse; mc._y = _root._ymouse; // add to array // places new movie clip trailNum into array and array is incremented for the next element trail.push(mc); trailNum++; Mouse trail

  35. // loops through the movie clips stored in array trail // if any ends up with alpha property less than 0, then they are removed from array and from the screen for(var i=trail.length-1;i>=0;i--) { // reduce alpha and scale trail[i]._alpha -= speed; trail[i]._xscale -= speed; trail[i]._yscale -= speed; // if this is one invisible, remove it if (trail[i]._alpha <= 0) { // remove array trail.splice(0,1); // remove movie clip trail[i].removeMovieClip(); } } } Mouse trail

More Related