ActionScript Lesson 2 -variables

Views:
 
Category: Entertainment
     
 

Presentation Description

No description available.

Comments

Presentation Transcript

Actionscript : 

Actionscript About variables

Variables scope : 

Variables scope Variables scope is only on the timeline. Scenario A: Set x=10 at frame 1 & y=20 at frame 5 Set trace ("X is: " + x + ", Y is: " + y) at frame 10 X is 10, Y is 20 Scenario B Set a trace ("X is: " + x + ", Y is: " + y) at frame 1 Set x=10 at frame 5 & y=20 at frame 10 X is: undefined, Y is: undefined

Slide 3: 

this refers to the actual object to which the script is attached (i.e. itself) _parent refers to the movie clip that contains the object to which the script is attached _root refers to the main Flash movie, which contains the entire hierarchy of objects In this discussion, let’s concentrate on _root. Say you create a Flash movie that

Code commenting : 

Code commenting //----------------------------- //Function Name: Name of Your Function //Function Date: 15/09/2003 //Input: Input Variables (e.g Color Variable (String)) //Output: Output Variables (e.g Hex Color Reference) //Revision Date: 28/09/2003: Added Non Numeric Error Checking //----------------------------- /*----------------------------- Function Name: Name of Your Function Function Date: 15/09/2003 Input: Input Variables (e.g Color Variable (String)) Output: Output Variables (e.g Hex Color Reference) Revision Date: 28/09/2003: Added Non Numeric Error Checking -----------------------------*/

Slide 5: 

This style of comment can be used to “comment out” entire blocks of code, like this: /* _root.Option_Button.onPress = function () { getURL ("http://www.google.com"); }; */

ActionScript is Case-Sensitive : 

ActionScript is Case-Sensitive function TestTrace () { trace ("hello"); } myButon.onRollOver = function () { testtrace (); }

Slide 7: 

Do create filenames that relate to the purpose or goals of the Flash project create names for functions and variables that indicate their roles in the project use underscores to separate words; avoid hyphens (-) be consistent in your application of the naming system you decide to use

Slide 8: 

Do Not use acronyms that make little or no sense shorten filenames create function, file, or variable names that require a Masters degree in Particle Science to decrypt use spaces or merge words together (light switch or lightswitch)

Timeline Effects : 

Timeline Effects These are available from the Insert menu after you’ve selected an object from the stage. You can access them at: Insert > Timeline Effects > Effect. Blur Expand Explode Fade In Fade Out Fly In Fly Out Grow Shrink Spin Left Spin Right Wipe In Wipe Out

Organize folders and layers with ease in Flash MX 2004. : 

Organize folders and layers with ease in Flash MX 2004.

Animation with action script : 

Animation with action script //animation of the square var endX = 100; //max x animation distance var endY = 100; //max x animation distance sq_mc.onEnterFrame = function() { if (this._x<endX) { this._x += 10; } if (this._y<endY) { this._y += 10; } }; Sq_mc

Sets start coordinates of square : 

Sets start coordinates of square //when movie loads sets squuare to 0,0 position _root.onLoad = function() { sq_mc._x = 0; sq_mc._y = 0; };

Moves Square to 0,0 : 

Moves Square to 0,0 sq_mc.onPress = function() { sq_mc._x = 0; sq_mc._y = 0; };

Moves Square on RollOver : 

Moves Square on RollOver //when u place sq_mc.onRollOver = function() { maxX = 470; maxY = 320; if (this._x<maxX) { this._x += 10; } if (this._y<maxY) { this._y += 10; } };

Slide 15: 

MovieClip._visible Availability Flash Player 4. Usage my_mc._visible:Boolean Description Property; a Boolean value that indicates whether the movie clip specified by my_mc is visible. Movie clips that are not visible (_visible property set to false) are disabled. For example, a button in a movie clip with _visible set to false cannot be clicked. Example The following example sets the _visible property for two movie clips called myMC1_mc and myMC2_mc. The property is set to true for one instance, and false for the other. Notice that myMC1_mc instance cannot be clicked after the _visible property is set to false. myMC1_mc.onRelease = function() { trace(this._name+"._visible = false"); this._visible = false; }; myMC2_mc.onRelease = function() { trace(this._name+"._alpha = 0"); this._alpha = 0; };

Slide 16: 

MovieClip._alpha Availability Flash Player 4. Usage my_mc._alpha:Number Description Property; the alpha transparency value of the movie clip specified by my_mc. Valid values are 0 (fully transparent) to 100 (fully opaque). The default value is 100. Objects in a movie clip with _alpha set to 0 are active, even though they are invisible. For example, you can still click a button in a movie clip whose _alpha property is set to 0. To disable the button completely, you can set the movie clip's _visible property to false. You can extend the methods and event handlers of the MovieClip class by creating a subclass. For more information, see "Assigning a class to a movie clip symbol" in Using ActionScript in Flash. Example The following code sets the _alpha property of a dynamically created movie clip named holder_mc to 50% when the mouse rolls over the movie clip. Add the following ActionScript to your FLA or AS file: this.createEmptyMovieClip("holder_mc", this.getNextHighestDepth()); holder_mc.createEmptyMovieClip("image_mc", holder_mc.getNextHighestDepth()); // replace with your own image or use the following holder_mc.image_mc.loadMovie("http://www.macromedia.com/devnet/mx/blueprint/articles/nielsen/spotlight_jnielsen.jpg"); holder_mc.onRollOver = function() { this._alpha = 50; }; holder_mc.onRollOut = function() { this._alpha = 100; };

Slide 17: 

MovieClip._currentframe Availability Flash Player 4. Usage my_mc._currentframe:Number Description Read-only property; returns the number of the frame in which the playhead is located in the Timeline specified by my_mc. Example The following example uses the _currentframe property to direct the playhead of the movie clip actionClip_mc to advance five frames ahead of its current location: actionClip_mc.gotoAndStop(actionClip_mc._currentframe + 5);

Slide 18: 

MovieClip._droptarget Availability Flash Player 4. Usage my_mc._droptarget:String Description Read-only property; returns the absolute path in slash syntax notation of the movie clip instance on which my_mc was dropped. The _droptarget property always returns a path that starts with a slash (/). To compare the _droptarget property of an instance to a reference, use the eval() function to convert the returned value from slash syntax to a dot syntax reference. Note: You must perform this conversion if you are using ActionScript 2.0, which does not support slash syntax. Example The following example evaluates the _droptarget property of the garbage_mc movie clip instance and uses eval() to convert it from slash syntax to a dot syntax reference. The garbage_mc reference is then compared to the reference to the trashcan_mc movie clip instance. If the two references are equivalent, the visibility of garbage_mc is set to false. If they are not equivalent, the garbage instance resets to its original position. origX = garbage_mc._x; origY = garbage_mc._y; garbage_mc.onPress = function() { this.startDrag(); }; garbage_mc.onRelease = function() { this.stopDrag(); if (eval(this._droptarget) == trashcan_mc) { this._visible = false; } else { this._x = origX; this._y = origY; } }; See also startDrag(), stopDrag()

Slide 19: 

MovieClip._height Availability Flash Player 4. Usage my_mc._height:Number Description Property; the height of the movie clip, in pixels. Example The following code example displays the height and width of a movie clip in the Output panel: this.createEmptyMovieClip("image_mc", this.getNextHighestDepth()); var image_mcl:MovieClipLoader = new MovieClipLoader(); var mclListener:Object = new Object(); mclListener.onLoadInit = function(target_mc:MovieClip) { trace(target_mc._name+" = "+target_mc._width+" X "+target_mc._height+" pixels"); }; image_mcl.addListener(mclListener); image_mcl.loadClip("http://www.macromedia.com/devnet/mx/blueprint/articles/nielsen/spotlight_jnielsen.jpg", image_mc); See Also MovieClip._width

Slide 20: 

MovieClip.onDragOut when the mouse button is pressed and the pointer rolls outside the object MovieClip.onDragOver when the pointer is dragged outside and then over the movie clip MovieClip.onEnterFrame invoked repeatedly at the frame rate of the SWF file. The actions associated with the enterFrame event are processed before any frame actions that are attached to the affected frames. MovieClip.onKeyDown invoked when a movie clip has input focus and a key is pressed keyListener.onKeyDown = function() { trace("The ASCII code for the last key typed is: "+Key.getAscii()); };

Slide 21: 

MovieClip.onMouseDown invoked when the mouse button is pressed MovieClip.onRollOver invoked when the pointer moves over a movie clip area MovieClip._rotation the rotation of the movie clip, in degrees, from its original orientation. Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation. MovieClip._width the width of the movie clip, in pixels. MovieClip._x an integer that sets the x coordinate of a movie clip relative to the local coordinates of the parent movie clip.

Slide 22: 

MovieClip._xmouse Read-only property; returns the x coordinate of the mouse position. MovieClip._xscale Property; determines the horizontal scale (percentage) of the movie clip as applied from the registration point of the movie clip. The default registration point is (0,0).

Slide 23: 

MovieClip.hitArea Availability Flash Player 6. Usage my_mc.hitArea:Object Returns A reference to a movie clip. Description Property; designates another movie clip to serve as the hit area for a movie clip. If the hitArea property does not exist or is null or undefined, the movie clip itself is used as the hit area. The value of the hitArea property may be a reference to a movie clip object. You can change the hitArea property at any time; the modified movie clip immediately takes on the new hit area behavior. The movie clip designated as the hit area does not need to be visible; its graphical shape, although not visible, is hit-tested. The hitArea property can be read out of a prototype object. Example The following example sets the circle_mc movie clip as the hit area for the square_mc movie clip. Place these two movie clips on the Stage and test the document. When you click circle_mc, the square_mc movie clip traces that it has been clicked. square_mc.hitArea = circle_mc; square_mc.onRelease = function() { trace("hit! "+this._name); }; You can also set the circle_mc movie clip visible property to false to hide the hit area for square_mc. circle_mc._visible = false; See Also MovieClip.hitTest()

Slide 24: 

MovieClip.hitTest() Availability Flash Player 5. Usage my_mc.hitTest(x:Number, y:Number, shapeFlag:Boolean) : Boolean my_mc.hitTest(target:Object) : Boolean Parameters x The x coordinate of the hit area on the Stage. y The y coordinate of the hit area on the Stage. The x and y coordinates are defined in the global coordinate space. target The target path of the hit area that may intersect or overlap with the instance specified by my_mc. The target parameter usually represents a button or text-entry field. shapeFlag A Boolean value specifying whether to evaluate the entire shape of the specified instance (true), or just the bounding box (false). This parameter can be specified only if the hit area is identified using x and y coordinate parameters. Returns A Boolean value of true if my_mc overlaps with the specified hit area, false otherwise. Description Method; evaluates the instance specified by my_mc to see if it overlaps or intersects with the hit area identified by the target or x and y coordinate parameters. Usage 1: Compares the x and y coordinates to the shape or bounding box of the specified instance, according to the shapeFlag setting. If shapeFlag is set to true, only the area actually occupied by the instance on the Stage is evaluated, and if x and y overlap at any point, a value of true is returned. This is useful for determining if the movie clip is within a specified hit or hotspot area. Usage 2: Evaluates the bounding boxes of the target and specified instance, and returns true if they overlap or intersect at any point. Example The following example uses hitTest() to determine if the movie clip circle_mc overlaps or intersects the movie clip square_mc when the user releases the mouse button: square_mc.onPress = function() { this.startDrag(); }; square_mc.onRelease = function() { this.stopDrag(); if (this.hitTest(circle_mc)) { trace("you hit the circle"); } };

Slide 25: 

a

Slide 26: 

a

Slide 27: 

a

Slide 28: 

a

Slide 29: 

a

Slide 30: 

a

Slide 31: 

a

Slide 32: 

a