Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Actionscript for Flash by Dr SC Li. 2 Understanding more about instances Symbolsgraphics buttons Movie clips Instances (without names) No interaction.

Similar presentations


Presentation on theme: "1 Actionscript for Flash by Dr SC Li. 2 Understanding more about instances Symbolsgraphics buttons Movie clips Instances (without names) No interaction."— Presentation transcript:

1 1 Actionscript for Flash by Dr SC Li

2 2 Understanding more about instances Symbolsgraphics buttons Movie clips Instances (without names) No interaction Vector Graphics Text dynamicstatic Variable names Instances (without names) Mouse interaction only Instances (with names) MovieClip interaction input Variable names

3 3 Paths to Instances Path to instances residing on Clip2: _root.Mary.John Main Stage Mary John

4 4 Paths to Instances Path to the text object: _root.level1.level2.level3.text ”text” Dynamic text field with variable name: ”text” Main Stage level1 level2 level3

5 5 on (mouseEvent)  Syntax  on (mouseEvent) {  ………..  }  Important  on(mouseEvent) ACTION can only be applied to BUTTON instances

6 6 On (mouseEvent) rollOver rollOutdragOver dragOut press release releaseOutside keyPress

7 7 on (mouseEvent)  press  The mouse button is pressed while the pointer is over the button.  release  The mouse button is released while the pointer is over the button.  releaseOutside  The mouse button is released while the pointer is outside the button.

8 8 on (mouseEvent)  rollOver  The mouse pointer rolls over the button.  rollOut  The pointer rolls outside of the button area.  dragOver  While the pointer is over the button, the mouse button has been pressed while rolled outside the button, and then rolled back over the button.

9 9 on (mouseEvent)  dragOut  While the pointer is over the button, the mouse button is pressed and then rolls outside the button area.  keyPress ("key")  The specified key is pressed. The key portion of the argument is specified using any of the key codes listed in the Appendix B, "Keyboard Keys and Key Code Values," or any of the key constants listed in the Property summary for the Key object.

10 10 OnClipEvent(???)  Any of the following values can be specified for the movieEvent argument:  load  The action is initiated as soon as the movie clip is instantiated and appears in the Timeline.  unload  The action is initiated in the first frame after the movie clip is removed from the Timeline. The actions associated with the Unload movie clip event are processed before any actions are attached to the affected frame.

11 11 OnClipEvent(???)  enterFrame  The action is initiated as each frame is played, similar to actions attached to a movie clip. The actions associated with the OnEnterFrame movie clip event are processed after any actions that are attached to the affected frames.  mouseMove  The action is initiated every time the mouse is moved. Use the _xmouse and _ymouse properties to determine the current mouse position.

12 12 OnClipEvent(???)  Syntax  onClipEvent (movieEvent) {  ………..  } A movieEvent is a trigger event that executes actions that are assigned to a movie clip instance.

13 13 OnClipEvent(MovieEvent) load unloadenterFrame data mouseMove mouseUpmouseDownkeyDown keyUp

14 14 OnClipEvent(???)  Any of the following values can be specified for the movieEvent argument:  load  The action is initiated as soon as the movie clip is instantiated and appears in the Timeline.  unload  The action is initiated in the first frame after the movie clip is removed from the Timeline. The actions associated with the Unload movie clip event are processed before any actions are attached to the affected frame.

15 15 OnClipEvent(???)  enterFrame  The action is initiated as each frame is played, similar to actions attached to a movie clip. The actions associated with the OnEnterFrame movie clip event are processed after any actions that are attached to the affected frames.  mouseMove  The action is initiated every time the mouse is moved. Use the _xmouse and _ymouse properties to determine the current mouse position.

16 16 OnClipEvent(???)  mouseDown  The action is initiated when the left mouse button is pressed.  mouseUp  The action is initiated when the left mouse button is released.  keyDown  The action is initiated when a key is pressed. Use the Key.getCode method to retrieve information about the last key pressed.

17 17 OnClipEvent(???)  keyUp  The action is initiated when a key is released. Use the Key.getCode method to retrieve information about the last key pressed.  data  The action is initiated when data is received in a loadVariables or loadMovie action. When specified with a loadVariables action, the data event occurs only once, when the last variable is loaded. When specified with a loadMovie action, the data event occurs repeatedly, as each section of data is retrieved.

18 18 Flash Actions

19 19 getProperty/setProperty  properties of an instance  _xscale, _yscale, _x, _y, _alpha, _rotation, ……….. etc.  actionscript (for a movie clip):  onClipEvent (mouseDown) {  dummy=getProperty(_target, _alpha)-10;  setProperty(_target, _alpha, dummy);  }

20 20 getProperty/setProperty  properties of an instance  _xscale, _yscale, _x, _y, _alpha, _rotation, ……….. etc.  actionscript (for a button):  on (press) {  dummy=getProperty(_target, _alpha)-10;  setProperty(_target, _alpha, dummy);  }

21 21 IF-ELSE statements  if(conditions){  statements …  }  else {  statements …  }  Example  if(dummy < 0){  setProperty(_target, _alpha, 100);  }  else {  setProperty(_target, _alpha, dummy);  }

22 22 Actionscript: Exercise 1 Changing the property of an instance (1)  Open the file action-ex1.fla Windows > Library  Open the library window by clicking Windows > Library  Drag the movie clip “ mouse ” from the library panel onto the main stage  Assign a name to the movie clip instance by highlighting it, then by right clicking it. Panels > Instance  Choose Panels > Instance and on the “ name field ”, type in the name for the instance.

23 23 Actionscript: Exercise 1  Insert an actionscript for the movie clip instance by highlighting it, then by right clicking it. Actions  Choose Actions and change the script editor to expert mode. Then type in the script:  onClipEvent (mouseDown) {  dummy=getProperty(_target, _alpha)-10;  setProperty(_target, _alpha, dummy);  }  Save the file and preview it.

24 24 Actionscript: Exercise 2 Changing the property of an instance (2)  Compare and contrast the two Flash movies: action-ex1-finished.swf and action-ex2- finished.swf  Open the file action-ex2.fla Windows > Library  Open the library window the library window by clicking Windows > Library Insert > New Symbols  Insert a new “ Movie Clip ” symbol by clicking Insert > New Symbols  Drag the button “ mouse_b ” from the library panel onto the movie clip stage

25 25 Actionscript: Exercise 2  Insert an actionscript for the button instance on movie clip stage by highlighting it, then by right clicking it.  Then turn to Scene 1 (the main stage) and drag the movie clip, “ mouse ” from the library panel onto the main stage.  Assign a name to the movie clip instance by highlighting it, then by right clicking it.

26 26 Actionscript: Exercise 2 Panels > Instance  Choose Panels > Instance and on the “ name field ”, type in the name, “ mouse ” for the instance. Actions  Choose Actions and change the script editor to expert mode. Then type in the script:  on (press) {  dummy=getProperty(_target, _alpha)-10;  setProperty(_target, _alpha, dummy);  }  Save the file and preview it.

27 27 Actionscript: Exercise 3 Changing the property with IF-ELSE  Open the file action-ex3.fla Windows > Library  Open the library window by clicking Windows > Library  Double-click the Movie Clip “ mouse ”  On the stage of the movie clip “ mouse ”, modify the actionscripts for the button instance as:

28 28 Actionscript: Exercise 3  Actionscript:  on (press) {  dummy=getProperty(_target, _alpha)-10;  if(dummy < 0){  setProperty(_target, _alpha, 100);  }  else {  setProperty(_target, _alpha, dummy);  } Save the file and preview it.

29 29 Actionscript: Exercise 4 Changing the position of an instance  Open the file action-ex4.fla  Follow similar steps given in exercise 2, modify the actionscript so that after clicking on the instance, its x position will be changed.

30 30 Actionscript: Exercise 5 Changing the orientation of an instance  Open the file action-ex5.fla  Follow similar steps given in exercise 2, modify the actionscript so that after clicking on the instance, it will be rotated to a certain degree.

31 31 Actionscript: Exercise 6 Displaying the property of an instance  Open the file action-ex6.fla  On the main stage, create dynamic text fields with appropriate names for the corresponding property items  Insert an actionscript for the button instance on the movie clip stage of “ mouse ” so that on clicking the instance, its properties will be displayed on the text boxes.

32 32 Actionscript: Exercise 6  Actionscript:  on (release) {  _root.xpos = getProperty ( _target, _x );  _root.ypos = getProperty ( _target, _y );  _root.alpha = getProperty ( _target, _alpha );  _root.rotation = getProperty ( _target, _rotation );  } Save the file and preview it.

33 33 Actionscript: Exercise 7 Changing the property of an instance (3)  Open the file action-ex7.fla  On the main stage, create dynamic text fields with appropriate names for the corresponding property items  Insert an actionscript for the yellow button instances on the main stage of so that on clicking the yellow button, the corresponding property of the “ mouse ” instance will be changed subsequently.

34 34 Actionscript: Exercise 7  Actionscript (for example):  on (release) {  setProperty (_root.mouse, _x, xpos);  } Save the file and preview it.

35 35 Actionscript: Exercise 8 Creating a draggable object  Open the file action-ex8.fla Windows > Library  Open the library window by clicking Windows > Library  Edit the movie clip “ mouse ” by double- clicking the clip on the library panel  On the stage for the mouse clip, there is an instance of the button “ mouse_b ”. Insert a mouse action for the button as follows:

36 36 Actionscript: Exercise 8  Change the script editor to expert mode  type in the script:  on (press) {  startDrag(this, true);  }  on (release){  stopDrag();  }  Save the file and preview it.


Download ppt "1 Actionscript for Flash by Dr SC Li. 2 Understanding more about instances Symbolsgraphics buttons Movie clips Instances (without names) No interaction."

Similar presentations


Ads by Google