SlideShare a Scribd company logo
1 of 25
ARTDM 170, Week 6: Using
 Objects + Scripting Motion
          Gilbert Guerrero
         gguerrero@dvc.edu
 gilbertguerrero.com/blog/artdm-170
Adobe Flash
Open Flash and create a new
 ActionScript 3.0 document...
Create an ActionScript class

• Save your ActionScript file, example:
  MyAnimation.fla
• Go to New... > ActionScript File   to
  create a new external AS file
• Save the file using the same name as
  your Flash file, example:

  MyAnimation.as
Review: ActionScript Class
                Class file declaration
package {                  Library classes needed
  import flash.display.*;
  import flash.text.*;                Class definition
    public class HelloWorld2 extends MovieClip {


        public function HelloWorld2() {
          var myText: TextField = new TextField();
          myText.text = "Hello World!";
          addChild(myText);
        }
    }                                   Constructor
}
Create a new AS class
 package {
   import flash.display.*;

     public class MyAnimation extends Sprite {


         public function MyAnimation() {

         }
     }
 }
Placing objects on the stage

• Programmatically (using Flash
  display objects)
• Library (named instances)
• Library + Programmatically (export
  for ActionScript)
Drawing a circle with code

• Add this code to your class to draw a
  circle on the screen
public var myCircle:Sprite = new Sprite();
myCircle.graphics.lineStyle(5,0x000000);
myCircle.graphics.beginFill(0xCCCCCC);
myCircle.graphics.drawCircle(0,0,25);
addChild(myCircle);
Draw a circle
•   Create a new movie clip
•   Draw a circle
•   Drag it onto the stage
•   Name the instance of the object
•   The instance name becomes the way to use
    the object in the code:
    //moves circle to the upper corner
    happyFunBall.x = 0;
    happyFunBall.y = 0;
Export for ActionScript

• Open the Properties for an object in
  the library
• Check export for ActionScript and
  click OK
• Flash will create a class for you
Export for ActionScript

• Now you can created an unlimited
 number of named instances in the
 code to add the object to the stage
var superFunBall:Ball = new Ball();
superFunBall.x = 0;
superFunBall.y = 0;
addChild(superFunBall);
Computer Animation
Moving objects

• An instance of a movie clip can be
 moved to any location using x and y
 as coordinates:
myCircle.x = 300;
myCircle.y = 200;
Updating location
• By updating x and y values we can change
 the location of our object


// Move the clips
 myCircle.x = myCircle.x + 10;
 myCircle.y = myCircle.y + 10;
Traditional Animation



  frame   frame   frame
     1       2       3
Computer Animation



 render       display    render       display
frame 1      frame 1    frame 2      frame 2




     Executes code          Executes code
(Dynamic) Flash Animation

                   There’s only one frame!


 get                                  apply
          render       display
initial                              rules to
           frame       frame
state                                 state
Event Listeners
•   By using an event listener that's triggered by
    ENTER_FRAME the movie clip instance will move on
    it's own
addEventListener(Event.ENTER_FRAME,
myFunction);
Movement function
public function onMoveCircle
  (e:Event):void {
    myCircle.x = myCircle.x + moveX;
    myCircle.y = myCircle.y + moveY;

}
Triggering movement
package {
	    import flash.display.*;
	    import flash.events.*;
	
	    public class MyAnimation extends MovieClip {
	    	
	    	    // Setup the values
	    	    private var myCircle:Sprite;
	    	
	    	    public function MyAnimation() {
	    	    	    myCircle = new Sprite();
	    	    	    myCircle.graphics.beginFill(0xCCCCCC);
	    	    	    myCircle.graphics.drawCircle(0,0,25);
	    	    	    addChild(theBall);
	    	    	    addEventListener(Event.ENTER_FRAME,
onMoveCircle);
	    	    }
	    	    public function onMoveCircle(pEvent:Event):void {
	    	        myCircle.x = myCircle.x + 10;
                myCircle.y = myCircle.y + 10;
	    	    }
	    }
}
Bounce the clip off the edges
•   The edge of the stage can be detected by
    determining if the movie clip's x or y values are
    greater or less than the stage width or height:
    myClip.x > stage.stageWidth 
    myClip.x < 0 
    myClip.y > stage.stageHeight

    myClip.y < 0  

•   stage.stageWidth and stage.stageHeight are
    variables stored by Flash that you can access at
    any time.
Change direction
•   The direction of the clip can be changed when an
    edge is detected:
if(myClip.x > stage.stageWidth || myClip.x < 0) {

        moveX = -moveX; 
    }  
if(myClip.y > stage.stageHeight || myClip.y < 0) {

        moveY = -moveY; 

    }  
Bounce the clip off the edges
// Setup the values
var moveX:Number = 10;
var moveY:Number = 10;
function moveClip(pEvent:Event):void {
    if(myClip.x > stage.stageWidth ||  myClip.x < 0){
        moveX = -moveX;  //change direction
    }    
    if(myClip.y > stage.stageHeight ||  myClip.y < 0){
        moveY = -moveY;  //change direction
    }    
    // Move the clips 
    myClip.x = myClip.x + moveX;
    myClip.y = myClip.y + moveY;
}
// Trigger the movement automatically
addEventListener(Event.ENTER_FRAME, moveClip);
Use the edge of the ball
For a more realistic bounce the edge of the ball should
be detected when it comes into contact with the edge. 
Do this by adding or subtracting half the width of the
ball:
myClip.width/2
myClip.height/2

The full statements:
myClip.x > stage.stageWidth - myClip.width/2 ||
myClip.x < myClip.width/2
myClip.y > stage.stageHeight - myClip.height/2 ||
myClip.y < myClip.height/2
Bounce using the ball edges
var moveX:Number = 10;
var moveY:Number = 10;

function moveClip(pEvent:Event):void {
    if(myClip.x > stage.stageWidth - myClip.width/2
||  myClip.x < myClip.width/2){
        moveX = -moveX;  //change direction
    }    
    if(myClip.y > stage.stageHeight - myClip.height/2
||  myClip.y < myClip.height/2){
        moveY = -moveY;  //change direction
    }   
    myClip.x = myClip.x + moveX;
    myClip.y = myClip.y + moveY;
}
Homework, due March 9

• Read p65-81, Chapter 2:
  ActionScript Game Elements in AS
  3.0 Game Programming University
• Create a Flash movie with scripted
  motion
 • Add an object to the stage
 • Make the object move across the
   screen using ActionScript

More Related Content

What's hot

10CSL67 CG LAB PROGRAM 10
10CSL67 CG LAB PROGRAM 1010CSL67 CG LAB PROGRAM 10
10CSL67 CG LAB PROGRAM 10Vanishree Arun
 
Introducing AlloyUI DiagramBuilder
Introducing AlloyUI DiagramBuilderIntroducing AlloyUI DiagramBuilder
Introducing AlloyUI DiagramBuilderEduardo Lundgren
 
YUI3 and AlloyUI Introduction for Pernambuco.JS 2012
YUI3 and AlloyUI Introduction for Pernambuco.JS 2012YUI3 and AlloyUI Introduction for Pernambuco.JS 2012
YUI3 and AlloyUI Introduction for Pernambuco.JS 2012Eduardo Lundgren
 
ARTDM 170, Week 13: Text Elements + Arrays
ARTDM 170, Week 13: Text Elements + ArraysARTDM 170, Week 13: Text Elements + Arrays
ARTDM 170, Week 13: Text Elements + ArraysGilbert Guerrero
 
Stupid Canvas Tricks
Stupid Canvas TricksStupid Canvas Tricks
Stupid Canvas Tricksdeanhudson
 
10CSL67 CG LAB PROGRAM 8
10CSL67 CG LAB PROGRAM 810CSL67 CG LAB PROGRAM 8
10CSL67 CG LAB PROGRAM 8Vanishree Arun
 
La 4 grafik komputer
La 4 grafik komputerLa 4 grafik komputer
La 4 grafik komputerYudo Rahadya
 

What's hot (8)

10CSL67 CG LAB PROGRAM 10
10CSL67 CG LAB PROGRAM 1010CSL67 CG LAB PROGRAM 10
10CSL67 CG LAB PROGRAM 10
 
Rxjs kyivjs 2015
Rxjs kyivjs 2015Rxjs kyivjs 2015
Rxjs kyivjs 2015
 
Introducing AlloyUI DiagramBuilder
Introducing AlloyUI DiagramBuilderIntroducing AlloyUI DiagramBuilder
Introducing AlloyUI DiagramBuilder
 
YUI3 and AlloyUI Introduction for Pernambuco.JS 2012
YUI3 and AlloyUI Introduction for Pernambuco.JS 2012YUI3 and AlloyUI Introduction for Pernambuco.JS 2012
YUI3 and AlloyUI Introduction for Pernambuco.JS 2012
 
ARTDM 170, Week 13: Text Elements + Arrays
ARTDM 170, Week 13: Text Elements + ArraysARTDM 170, Week 13: Text Elements + Arrays
ARTDM 170, Week 13: Text Elements + Arrays
 
Stupid Canvas Tricks
Stupid Canvas TricksStupid Canvas Tricks
Stupid Canvas Tricks
 
10CSL67 CG LAB PROGRAM 8
10CSL67 CG LAB PROGRAM 810CSL67 CG LAB PROGRAM 8
10CSL67 CG LAB PROGRAM 8
 
La 4 grafik komputer
La 4 grafik komputerLa 4 grafik komputer
La 4 grafik komputer
 

Viewers also liked

ARTDM 170, Week10: Arrays + Using Randomization
ARTDM 170, Week10: Arrays + Using RandomizationARTDM 170, Week10: Arrays + Using Randomization
ARTDM 170, Week10: Arrays + Using RandomizationGilbert Guerrero
 
ARTDM 171, Week 10: Navigation Schemes
ARTDM 171, Week 10: Navigation SchemesARTDM 171, Week 10: Navigation Schemes
ARTDM 171, Week 10: Navigation SchemesGilbert Guerrero
 
A R T D M171 Week14 Multimedia
A R T D M171  Week14  MultimediaA R T D M171  Week14  Multimedia
A R T D M171 Week14 MultimediaGilbert Guerrero
 
Newsroom Transformation
Newsroom TransformationNewsroom Transformation
Newsroom TransformationSteve Buttry
 
Artdm170 Week4 Java Script Effects
Artdm170 Week4 Java Script EffectsArtdm170 Week4 Java Script Effects
Artdm170 Week4 Java Script EffectsGilbert Guerrero
 

Viewers also liked (6)

ARTDM 170, Week10: Arrays + Using Randomization
ARTDM 170, Week10: Arrays + Using RandomizationARTDM 170, Week10: Arrays + Using Randomization
ARTDM 170, Week10: Arrays + Using Randomization
 
ARTDM 171, Week 10: Navigation Schemes
ARTDM 171, Week 10: Navigation SchemesARTDM 171, Week 10: Navigation Schemes
ARTDM 171, Week 10: Navigation Schemes
 
A R T D M171 Week14 Multimedia
A R T D M171  Week14  MultimediaA R T D M171  Week14  Multimedia
A R T D M171 Week14 Multimedia
 
ARTDM 171, Week 13: Forms
ARTDM 171, Week 13: FormsARTDM 171, Week 13: Forms
ARTDM 171, Week 13: Forms
 
Newsroom Transformation
Newsroom TransformationNewsroom Transformation
Newsroom Transformation
 
Artdm170 Week4 Java Script Effects
Artdm170 Week4 Java Script EffectsArtdm170 Week4 Java Script Effects
Artdm170 Week4 Java Script Effects
 

Similar to Artdm170 Week6 Scripting Motion

Artdm170 Week5 Intro To Flash
Artdm170 Week5 Intro To FlashArtdm170 Week5 Intro To Flash
Artdm170 Week5 Intro To FlashGilbert Guerrero
 
ARTDM 170, Week 5: Intro To Flash
ARTDM 170, Week 5: Intro To FlashARTDM 170, Week 5: Intro To Flash
ARTDM 170, Week 5: Intro To FlashGilbert Guerrero
 
ARTDM 170 Week 8: Scripting Interactivity
ARTDM 170 Week 8: Scripting InteractivityARTDM 170 Week 8: Scripting Interactivity
ARTDM 170 Week 8: Scripting InteractivityGilbert Guerrero
 
Im flash
Im flashIm flash
Im flashhuanwu
 
Useful Tools for Making Video Games - XNA (2008)
Useful Tools for Making Video Games - XNA (2008)Useful Tools for Making Video Games - XNA (2008)
Useful Tools for Making Video Games - XNA (2008)Korhan Bircan
 
HTML5 Canvas - Let's Draw!
HTML5 Canvas - Let's Draw!HTML5 Canvas - Let's Draw!
HTML5 Canvas - Let's Draw!Phil Reither
 
Intro to computer vision in .net
Intro to computer vision in .netIntro to computer vision in .net
Intro to computer vision in .netStephen Lorello
 
Leaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGLLeaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGLgerbille
 
14multithreaded Graphics
14multithreaded Graphics14multithreaded Graphics
14multithreaded GraphicsAdil Jafri
 
HTML5 Animation in Mobile Web Games
HTML5 Animation in Mobile Web GamesHTML5 Animation in Mobile Web Games
HTML5 Animation in Mobile Web Gameslivedoor
 
Enhancing UI/UX using Java animations
Enhancing UI/UX using Java animationsEnhancing UI/UX using Java animations
Enhancing UI/UX using Java animationsNaman Dwivedi
 
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...DroidConTLV
 
Oculus Rift DK2 + Leap Motion Tutorial
Oculus Rift DK2 + Leap Motion TutorialOculus Rift DK2 + Leap Motion Tutorial
Oculus Rift DK2 + Leap Motion TutorialChris Zaharia
 
Coding Flash : ActionScript(3.0) Tutorial
Coding Flash :  ActionScript(3.0) TutorialCoding Flash :  ActionScript(3.0) Tutorial
Coding Flash : ActionScript(3.0) TutorialPEI-YAO HUNG
 
Stop running from animations droidcon London
Stop running from animations droidcon LondonStop running from animations droidcon London
Stop running from animations droidcon Londonmaric_iv
 

Similar to Artdm170 Week6 Scripting Motion (20)

Artdm170 Week5 Intro To Flash
Artdm170 Week5 Intro To FlashArtdm170 Week5 Intro To Flash
Artdm170 Week5 Intro To Flash
 
ARTDM 170, Week 5: Intro To Flash
ARTDM 170, Week 5: Intro To FlashARTDM 170, Week 5: Intro To Flash
ARTDM 170, Week 5: Intro To Flash
 
ARTDM 170 Week 8: Scripting Interactivity
ARTDM 170 Week 8: Scripting InteractivityARTDM 170 Week 8: Scripting Interactivity
ARTDM 170 Week 8: Scripting Interactivity
 
Intro to HTML5
Intro to HTML5Intro to HTML5
Intro to HTML5
 
Im flash
Im flashIm flash
Im flash
 
Useful Tools for Making Video Games - XNA (2008)
Useful Tools for Making Video Games - XNA (2008)Useful Tools for Making Video Games - XNA (2008)
Useful Tools for Making Video Games - XNA (2008)
 
HTML5 Canvas - Let's Draw!
HTML5 Canvas - Let's Draw!HTML5 Canvas - Let's Draw!
HTML5 Canvas - Let's Draw!
 
Intro to computer vision in .net
Intro to computer vision in .netIntro to computer vision in .net
Intro to computer vision in .net
 
Leaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGLLeaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGL
 
Shootting Game
Shootting GameShootting Game
Shootting Game
 
Prototype UI
Prototype UIPrototype UI
Prototype UI
 
14multithreaded Graphics
14multithreaded Graphics14multithreaded Graphics
14multithreaded Graphics
 
HTML5 Animation in Mobile Web Games
HTML5 Animation in Mobile Web GamesHTML5 Animation in Mobile Web Games
HTML5 Animation in Mobile Web Games
 
Enhancing UI/UX using Java animations
Enhancing UI/UX using Java animationsEnhancing UI/UX using Java animations
Enhancing UI/UX using Java animations
 
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
 
Oculus Rift DK2 + Leap Motion Tutorial
Oculus Rift DK2 + Leap Motion TutorialOculus Rift DK2 + Leap Motion Tutorial
Oculus Rift DK2 + Leap Motion Tutorial
 
Coding Flash : ActionScript(3.0) Tutorial
Coding Flash :  ActionScript(3.0) TutorialCoding Flash :  ActionScript(3.0) Tutorial
Coding Flash : ActionScript(3.0) Tutorial
 
Stop running from animations droidcon London
Stop running from animations droidcon LondonStop running from animations droidcon London
Stop running from animations droidcon London
 
Sbaw091117
Sbaw091117Sbaw091117
Sbaw091117
 
iOS Training Session-3
iOS Training Session-3iOS Training Session-3
iOS Training Session-3
 

More from Gilbert Guerrero

Designing for Skepticism and Bright Sunlight
Designing for Skepticism and Bright SunlightDesigning for Skepticism and Bright Sunlight
Designing for Skepticism and Bright SunlightGilbert Guerrero
 
ARTDM 171, Week 17: Usability Testing and QA
ARTDM 171, Week 17: Usability Testing and QAARTDM 171, Week 17: Usability Testing and QA
ARTDM 171, Week 17: Usability Testing and QAGilbert Guerrero
 
Artdm 170 week15 publishing
Artdm 170 week15 publishingArtdm 170 week15 publishing
Artdm 170 week15 publishingGilbert Guerrero
 
ARTDM 170, Week 14: Introduction to Processing
ARTDM 170, Week 14: Introduction to ProcessingARTDM 170, Week 14: Introduction to Processing
ARTDM 170, Week 14: Introduction to ProcessingGilbert Guerrero
 
ARTDM 171, Week 13: Navigation Schemes
ARTDM 171, Week 13: Navigation SchemesARTDM 171, Week 13: Navigation Schemes
ARTDM 171, Week 13: Navigation SchemesGilbert Guerrero
 
Artdm170 week12 user_interaction
Artdm170 week12 user_interactionArtdm170 week12 user_interaction
Artdm170 week12 user_interactionGilbert Guerrero
 
Artdm 171 Week12 Templates
Artdm 171 Week12 TemplatesArtdm 171 Week12 Templates
Artdm 171 Week12 TemplatesGilbert Guerrero
 
ARTDM 171, Week 10: Mood Boards + Page Comps
ARTDM 171, Week 10: Mood Boards + Page CompsARTDM 171, Week 10: Mood Boards + Page Comps
ARTDM 171, Week 10: Mood Boards + Page CompsGilbert Guerrero
 
ARTDM 170, Week 10: Encapsulation + Paper Prototypes
ARTDM 170, Week 10: Encapsulation + Paper PrototypesARTDM 170, Week 10: Encapsulation + Paper Prototypes
ARTDM 170, Week 10: Encapsulation + Paper PrototypesGilbert Guerrero
 
ARTDM 171, Week 9: User Experience
ARTDM 171, Week 9: User ExperienceARTDM 171, Week 9: User Experience
ARTDM 171, Week 9: User ExperienceGilbert Guerrero
 
ARTDM 171, Week 7: Remapping Cyberspace
ARTDM 171, Week 7: Remapping CyberspaceARTDM 171, Week 7: Remapping Cyberspace
ARTDM 171, Week 7: Remapping CyberspaceGilbert Guerrero
 
ARTDM 170, Week 7: Scripting Interactivity
ARTDM 170, Week 7: Scripting InteractivityARTDM 170, Week 7: Scripting Interactivity
ARTDM 170, Week 7: Scripting InteractivityGilbert Guerrero
 
Artdm170 week6 scripting_motion
Artdm170 week6 scripting_motionArtdm170 week6 scripting_motion
Artdm170 week6 scripting_motionGilbert Guerrero
 
Artdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting MotionArtdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting MotionGilbert Guerrero
 
Artdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting MotionArtdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting MotionGilbert Guerrero
 
Artdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting MotionArtdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting MotionGilbert Guerrero
 

More from Gilbert Guerrero (20)

Designing for Skepticism and Bright Sunlight
Designing for Skepticism and Bright SunlightDesigning for Skepticism and Bright Sunlight
Designing for Skepticism and Bright Sunlight
 
ARTDM 171, Week 17: Usability Testing and QA
ARTDM 171, Week 17: Usability Testing and QAARTDM 171, Week 17: Usability Testing and QA
ARTDM 171, Week 17: Usability Testing and QA
 
Artdm 171 week15 seo
Artdm 171 week15 seoArtdm 171 week15 seo
Artdm 171 week15 seo
 
Artdm 170 week15 publishing
Artdm 170 week15 publishingArtdm 170 week15 publishing
Artdm 170 week15 publishing
 
ARTDM 171, Week 14: Forms
ARTDM 171, Week 14: FormsARTDM 171, Week 14: Forms
ARTDM 171, Week 14: Forms
 
ARTDM 170, Week 14: Introduction to Processing
ARTDM 170, Week 14: Introduction to ProcessingARTDM 170, Week 14: Introduction to Processing
ARTDM 170, Week 14: Introduction to Processing
 
ARTDM 171, Week 13: Navigation Schemes
ARTDM 171, Week 13: Navigation SchemesARTDM 171, Week 13: Navigation Schemes
ARTDM 171, Week 13: Navigation Schemes
 
Artdm170 week12 user_interaction
Artdm170 week12 user_interactionArtdm170 week12 user_interaction
Artdm170 week12 user_interaction
 
Artdm 171 Week12 Templates
Artdm 171 Week12 TemplatesArtdm 171 Week12 Templates
Artdm 171 Week12 Templates
 
ARTDM 171, Week 10: Mood Boards + Page Comps
ARTDM 171, Week 10: Mood Boards + Page CompsARTDM 171, Week 10: Mood Boards + Page Comps
ARTDM 171, Week 10: Mood Boards + Page Comps
 
ARTDM 170, Week 10: Encapsulation + Paper Prototypes
ARTDM 170, Week 10: Encapsulation + Paper PrototypesARTDM 170, Week 10: Encapsulation + Paper Prototypes
ARTDM 170, Week 10: Encapsulation + Paper Prototypes
 
ARTDM 171, Week 9: User Experience
ARTDM 171, Week 9: User ExperienceARTDM 171, Week 9: User Experience
ARTDM 171, Week 9: User Experience
 
ARTDM 171, Week 7: Remapping Cyberspace
ARTDM 171, Week 7: Remapping CyberspaceARTDM 171, Week 7: Remapping Cyberspace
ARTDM 171, Week 7: Remapping Cyberspace
 
ARTDM 170, Week 7: Scripting Interactivity
ARTDM 170, Week 7: Scripting InteractivityARTDM 170, Week 7: Scripting Interactivity
ARTDM 170, Week 7: Scripting Interactivity
 
Artdm170 week6 scripting_motion
Artdm170 week6 scripting_motionArtdm170 week6 scripting_motion
Artdm170 week6 scripting_motion
 
Artdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting MotionArtdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting Motion
 
Artdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting MotionArtdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting Motion
 
Artdm171 Week6 Images
Artdm171 Week6 ImagesArtdm171 Week6 Images
Artdm171 Week6 Images
 
Artdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting MotionArtdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting Motion
 
Artdm171 Week5 Css
Artdm171 Week5 CssArtdm171 Week5 Css
Artdm171 Week5 Css
 

Recently uploaded

CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 

Recently uploaded (20)

CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 

Artdm170 Week6 Scripting Motion

  • 1. ARTDM 170, Week 6: Using Objects + Scripting Motion Gilbert Guerrero gguerrero@dvc.edu gilbertguerrero.com/blog/artdm-170
  • 2. Adobe Flash Open Flash and create a new ActionScript 3.0 document...
  • 3. Create an ActionScript class • Save your ActionScript file, example: MyAnimation.fla • Go to New... > ActionScript File to create a new external AS file • Save the file using the same name as your Flash file, example: MyAnimation.as
  • 4. Review: ActionScript Class Class file declaration package { Library classes needed import flash.display.*; import flash.text.*; Class definition public class HelloWorld2 extends MovieClip { public function HelloWorld2() { var myText: TextField = new TextField(); myText.text = "Hello World!"; addChild(myText); } } Constructor }
  • 5. Create a new AS class package { import flash.display.*; public class MyAnimation extends Sprite { public function MyAnimation() { } } }
  • 6. Placing objects on the stage • Programmatically (using Flash display objects) • Library (named instances) • Library + Programmatically (export for ActionScript)
  • 7. Drawing a circle with code • Add this code to your class to draw a circle on the screen public var myCircle:Sprite = new Sprite(); myCircle.graphics.lineStyle(5,0x000000); myCircle.graphics.beginFill(0xCCCCCC); myCircle.graphics.drawCircle(0,0,25); addChild(myCircle);
  • 8. Draw a circle • Create a new movie clip • Draw a circle • Drag it onto the stage • Name the instance of the object • The instance name becomes the way to use the object in the code: //moves circle to the upper corner happyFunBall.x = 0; happyFunBall.y = 0;
  • 9. Export for ActionScript • Open the Properties for an object in the library • Check export for ActionScript and click OK • Flash will create a class for you
  • 10. Export for ActionScript • Now you can created an unlimited number of named instances in the code to add the object to the stage var superFunBall:Ball = new Ball(); superFunBall.x = 0; superFunBall.y = 0; addChild(superFunBall);
  • 12. Moving objects • An instance of a movie clip can be moved to any location using x and y as coordinates: myCircle.x = 300; myCircle.y = 200;
  • 13. Updating location • By updating x and y values we can change the location of our object // Move the clips myCircle.x = myCircle.x + 10; myCircle.y = myCircle.y + 10;
  • 14. Traditional Animation frame frame frame 1 2 3
  • 15. Computer Animation render display render display frame 1 frame 1 frame 2 frame 2 Executes code Executes code
  • 16. (Dynamic) Flash Animation There’s only one frame! get apply render display initial rules to frame frame state state
  • 17. Event Listeners • By using an event listener that's triggered by ENTER_FRAME the movie clip instance will move on it's own addEventListener(Event.ENTER_FRAME, myFunction);
  • 18. Movement function public function onMoveCircle (e:Event):void { myCircle.x = myCircle.x + moveX; myCircle.y = myCircle.y + moveY; }
  • 19. Triggering movement package { import flash.display.*; import flash.events.*; public class MyAnimation extends MovieClip { // Setup the values private var myCircle:Sprite; public function MyAnimation() { myCircle = new Sprite(); myCircle.graphics.beginFill(0xCCCCCC); myCircle.graphics.drawCircle(0,0,25); addChild(theBall); addEventListener(Event.ENTER_FRAME, onMoveCircle); } public function onMoveCircle(pEvent:Event):void {     myCircle.x = myCircle.x + 10; myCircle.y = myCircle.y + 10; } } }
  • 20. Bounce the clip off the edges • The edge of the stage can be detected by determining if the movie clip's x or y values are greater or less than the stage width or height: myClip.x > stage.stageWidth  myClip.x < 0  myClip.y > stage.stageHeight myClip.y < 0   • stage.stageWidth and stage.stageHeight are variables stored by Flash that you can access at any time.
  • 21. Change direction • The direction of the clip can be changed when an edge is detected: if(myClip.x > stage.stageWidth || myClip.x < 0) {         moveX = -moveX;      }   if(myClip.y > stage.stageHeight || myClip.y < 0) {         moveY = -moveY;      }  
  • 22. Bounce the clip off the edges // Setup the values var moveX:Number = 10; var moveY:Number = 10; function moveClip(pEvent:Event):void {     if(myClip.x > stage.stageWidth ||  myClip.x < 0){         moveX = -moveX;  //change direction     }         if(myClip.y > stage.stageHeight ||  myClip.y < 0){         moveY = -moveY;  //change direction     }         // Move the clips      myClip.x = myClip.x + moveX;     myClip.y = myClip.y + moveY; } // Trigger the movement automatically addEventListener(Event.ENTER_FRAME, moveClip);
  • 23. Use the edge of the ball For a more realistic bounce the edge of the ball should be detected when it comes into contact with the edge.  Do this by adding or subtracting half the width of the ball: myClip.width/2 myClip.height/2 The full statements: myClip.x > stage.stageWidth - myClip.width/2 || myClip.x < myClip.width/2 myClip.y > stage.stageHeight - myClip.height/2 || myClip.y < myClip.height/2
  • 24. Bounce using the ball edges var moveX:Number = 10; var moveY:Number = 10; function moveClip(pEvent:Event):void {     if(myClip.x > stage.stageWidth - myClip.width/2 ||  myClip.x < myClip.width/2){         moveX = -moveX;  //change direction     }         if(myClip.y > stage.stageHeight - myClip.height/2 ||  myClip.y < myClip.height/2){         moveY = -moveY;  //change direction     }        myClip.x = myClip.x + moveX;     myClip.y = myClip.y + moveY; }
  • 25. Homework, due March 9 • Read p65-81, Chapter 2: ActionScript Game Elements in AS 3.0 Game Programming University • Create a Flash movie with scripted motion • Add an object to the stage • Make the object move across the screen using ActionScript

Editor's Notes