Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 100 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
100
Dung lượng
371,74 KB
Nội dung
MovieClip.beginGradientFill() 501 Returns Nothing. Description Method; indicates the beginning of a new drawing path. If the first parameter is undefined, or if no parameters are passed, the path has no fill. If an open path exists (that is if the current drawing position does not equal the previous position specified in a MovieClip.moveTo() method), and it has a fill associated with it, that path is closed with a line and then filled. This is similar to what happens when you call MovieClip.endFill() . This method fails if any of the following conditions exist: • The number of items in the colors , alphas , and ratios parameters are not equal. • The fillType parameter is not "linear" or "radial" . • Any of the fields in the object for the matrix parameter are missing or invalid. 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 uses both methods to draw two stacked rectangles with a red-blue gradient fill and a 5-pixel solid lime green stroke: this.createEmptyMovieClip("gradient_mc", 1); with (gradient_mc) { colors = [0xFF0000, 0x0000FF]; alphas = [100, 100]; ratios = [0, 0xFF]; lineStyle(5, 0x00ff00); matrix = {a:500, b:0, c:0, d:0, e:200, f:0, g:350, h:200, i:1}; beginGradientFill("linear", colors, alphas, ratios, matrix); moveTo(100, 100); lineTo(100, 300); lineTo(600, 300); lineTo(600, 100); lineTo(100, 100); endFill(); matrix = {matrixType:"box", x:100, y:310, w:500, h:200, r:(0/180)*Math.PI}; beginGradientFill("linear", colors, alphas, ratios, matrix); moveTo(100, 310); lineTo(100, 510); lineTo(600, 510); lineTo(600, 310); lineTo(100, 310); 502 Chapter 2: ActionScriptLanguage Reference endFill(); } See also MovieClip.beginFill(), MovieClip.endFill(), MovieClip.lineStyle(), MovieClip.lineTo(), MovieClip.moveTo() MovieClip.clear() 503 MovieClip.clear() Availability Flash Player 6. Usage my_mc.clear() : Void Parameters None. Returns Nothing. Description Method; removes all the graphics created during runtime using the movie clip draw methods, including line styles specified with MovieClip.lineStyle() . Shapes and lines that are manually drawn during authoring time (with the Flash drawing tools) are unaffected. Example The following example draws a box on the Stage. When the user clicks the box graphic, it removes the graphic from the Stage. this.createEmptyMovieClip("box_mc", this.getNextHighestDepth()); box_mc.onRelease = function() { this.clear(); }; drawBox(box_mc, 10, 10, 320, 240); function drawBox(mc:MovieClip, x:Number, y:Number, w:Number, h:Number):Void { mc.lineStyle(0); mc.beginFill(0xEEEEEE); mc.moveTo(x, y); mc.lineTo(x+w, y); mc.lineTo(x+w, y+h); mc.lineTo(x, y+h); mc.lineTo(x, y); mc.endFill(); } An example is also in the drawingapi.fla file in the HelpExamples folder. The following list gives typical paths to this folder: • Windows: \Program Files\Macromedia\Flash MX 2004\Samples\HelpExamples\ • Macintosh: HD/Applications/Macromedia Flash MX 2004/Samples/HelpExamples/ See also MovieClip.lineStyle() 504 Chapter 2: ActionScriptLanguage Reference MovieClip.createEmptyMovieClip() Availability Flash Player 6. Usage my_mc.createEmptyMovieClip(instanceName:String, depth:Number) : MovieClip Parameters instanceName A string that identifies the instance name of the new movie clip. depth An integer that specifies the depth of the new movie clip. Returns A reference to the newly created movie clip. Description Method; creates an empty movie clip as a child of an existing movie clip. This method behaves similarly to the attachMovie() method, but you don’t need to provide an external linkage identifier for the new movie clip. The registration point for a newly created empty movie clip is the upper left corner. This method fails if any of the parameters are missing. 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 ActionScript creates a new movie clip at runtime and loads a JPEG image into the movie clip. this.createEmptyMovieClip("logo_mc", this.getNextHighestDepth()); logo_mc.loadMovie("http://www.macromedia.com/images/shared/product_boxes/ 80x92/studio_flashpro.jpg"); See also MovieClip.attachMovie() MovieClip.createTextField() 505 MovieClip.createTextField() Availability Flash Player 6. Usage my_mc.createTextField(instanceName:String, depth:Number, x:Number, y:Number, width:Number, height:Number) : Void Parameters instanceName A string that identifies the instance name of the new text field. depth A positive integer that specifies the depth of the new text field. x An integer that specifies the x coordinate of the new text field. y An integer that specifies the y coordinate of the new text field. width A positive integer that specifies the width of the new text field. height A positive integer that specifies the height of the new text field. Returns Nothing. Description Method; creates a new, empty text field as a child of the movie clip specified by my_mc . You can use createTextField() to create text fields while a SWF file plays. The depth parameter determines the new text field’s z-order position in the movie clip. Each position in the z-order can contain only one object. If you create a new text field on a depth that already has a text field, the new text field will replace the existing text field. To avoid overwriting existing text fields, use the MovieClip.getInstanceAtDepth() to determine whether a specific depth is already occupied, or MovieClip.getNextHighestDepth() , to determine the highest unoccupied depth. The text field is positioned at ( x , y ) with dimensions width by height . The x and y parameters are relative to the container movie clip; these parameters correspond to the _x and _y properties of the text field. The width and height parameters correspond to the _width and _height properties of the text field. The default properties of a text field are as follows: type = "dynamic" border = false background = false password = false multiline = false html = false embedFonts = false selectable = true wordWrap = false mouseWheelEnabled = true condenseWhite = false restrict = null 506 Chapter 2: ActionScriptLanguage Reference variable = null maxChars = null styleSheet = undefined tabInded = undefined A text field created with createTextField() receives the following default TextFormat object: font = "Times New Roman" size = 12 color = 0x000000 bold = false italic = false underline = false url = "" target = "" align = "left" leftMargin = 0 rightMargin = 0 indent = 0 leading = 0 blockIndent = 0 bullet = false display = block tabStops = [] (empty array) 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 example creates a text field with a width of 300, a height of 100, an x coordinate of 100, a y coordinate of 100, no border, red, and underlined text: this.createTextField("my_txt", 1, 100, 100, 300, 100); my_txt.multiline = true; my_txt.wordWrap = true; var my_fmt:TextFormat = new TextFormat(); my_fmt.color = 0xFF0000; my_fmt.underline = true; my_txt.text = "This is my first test field object text."; my_txt.setTextFormat(my_fmt); An example is also in the animations.fla file in the HelpExamples folder. The following list gives typical paths to this folder: • Windows: \Program Files\Macromedia\Flash MX 2004\HelpExamples\ • Macintosh: HD/Applications/Macromedia Flash MX 2004/HelpExamples/ See also TextFormat class MovieClip._currentframe 507 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); 508 Chapter 2: ActionScriptLanguage Reference MovieClip.curveTo() Availability Flash Player 6. Usage my_mc.curveTo(controlX:Number, controlY:Number, anchorX:Number, anchorY:Number) : Void Parameters controlX An integer that specifies the horizontal position of the control point relative to the registration point of the parent movie clip. controlY An integer that specifies the vertical position of the control point relative to the registration point of the parent movie clip. anchorX An integer that specifies the horizontal position of the next anchor point relative to the registration. point of the parent movie clip. anchorY An integer that specifies the vertical position of the next anchor point relative to the registration point of the parent movie clip. Returns Nothing. Description Method; draws a curve using the current line style from the current drawing position to ( anchorX , anchorY ) using the control point specified by ( controlX , controlY ). The current drawing position is then set to ( anchorX , anchorY ). If the movie clip you are drawing in contains content created with the Flash drawing tools, calls to curveTo() are drawn underneath this content. If you call curveTo() before any calls to moveTo() , the current drawing position defaults to (0, 0). If any of the parameters are missing, this method fails and the current drawing position is not changed. 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 example draws a circle with a solid blue hairline stroke and a solid red fill: this.createEmptyMovieClip("circle_mc", 1); with (circle_mc) { lineStyle(0, 0x0000FF, 100); beginFill(0xFF0000); moveTo(500, 500); curveTo(600, 500, 600, 400); curveTo(600, 300, 500, 300); curveTo(400, 300, 400, 400); curveTo(400, 500, 500, 500); endFill(); } MovieClip.curveTo() 509 The curve drawn in this example is a quadratic bezier curve. Quadratic bezier curves consist of two anchor points and a control point. The curve interpolates the two anchor points, and curves toward the control point. The following ActionScript creates a circle using MovieClip.curveTo() and the Math class: this.createEmptyMovieClip("circle2_mc", 2); circle2_mc.lineStyle(0, 0x000000); drawCircle(circle2_mc, 10, 10, 100); function drawCircle(mc:MovieClip, x:Number, y:Number, r:Number):Void { mc.moveTo(x+r, y); mc.curveTo(r+x, Math.tan(Math.PI/8)*r+y, Math.sin(Math.PI/4)*r+x, Math.sin(Math.PI/4)*r+y); mc.curveTo(Math.tan(Math.PI/8)*r+x, r+y, x, r+y); mc.curveTo(-Math.tan(Math.PI/8)*r+x, r+y, -Math.sin(Math.PI/4)*r+x, Math.sin(Math.PI/4)*r+y); mc.curveTo(-r+x, Math.tan(Math.PI/8)*r+y, -r+x, y); mc.curveTo(-r+x, -Math.tan(Math.PI/8)*r+y, -Math.sin(Math.PI/4)*r+x, - Math.sin(Math.PI/4)*r+y); mc.curveTo(-Math.tan(Math.PI/8)*r+x, -r+y, x, -r+y); mc.curveTo(Math.tan(Math.PI/8)*r+x, -r+y, Math.sin(Math.PI/4)*r+x, - Math.sin(Math.PI/4)*r+y); mc.curveTo(r+x, -Math.tan(Math.PI/8)*r+y, r+x, y); } An example is also in the drawingapi.fla file in the HelpExamples folder. The following list gives typical paths to this folder: • Windows: \Program Files\Macromedia\Flash MX 2004\Samples\HelpExamples\ • Macintosh: HD/Applications/Macromedia Flash MX 2004/Samples/HelpExamples/ See also MovieClip.beginFill(), MovieClip.createEmptyMovieClip(), MovieClip.endFill(), MovieClip.lineStyle(), MovieClip.lineTo(), MovieClip.moveTo() 510 Chapter 2: ActionScriptLanguage Reference 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() [...]... class to a movie clip symbol” in Using ActionScript in Flash Example The following ActionScript displays the Flash Player version for the SWF file and for a SWF file that loads into a movie clip instance called fp6_mc trace(this.getSWFVersion()); // output: 7 fp6_mc.loadMovie("flashplayer6.swf"); my_btn.onRelease = function(){ trace("Loaded Flash Player " + fp6_mc.getSWFVersion() + " file."); //output:... Frame 3: stop(); See also MovieClip.getBytesLoaded() 520 Chapter 2: ActionScriptLanguage Reference MovieClip.getDepth() Availability Flash Player 6 Usage my_mc.getDepth() : Number Parameters None Returns An integer Description Method; returns the depth of a movie clip instance For more information, see “Managing movie clip depths” in Using ActionScript in Flash You can extend the methods and event handlers... (this._framesloaded > > > 110 10 110 10 MovieClip.getBounds() 517 See also MovieClip.globalToLocal(), MovieClip.localToGlobal() 518 Chapter 2: ActionScriptLanguage Reference MovieClip.getBytesLoaded() Availability Flash Player 5 Usage my_mc.getBytesLoaded() : Number Parameters None Returns An integer indicating the number of bytes loaded Description... “Assigning a class to a movie clip symbol” in Using ActionScript in Flash Example The following example uses the _framesloaded property to start a SWF file when all the frames are loaded If all the frames aren’t loaded, the _xscale property of the movie clip instance loader is increased proportionally to create a progress bar Enter the following ActionScript in Frame 1 of the Timeline: var pctLoaded:Number... “Assigning a class to a movie clip symbol” in Using ActionScript in Flash Example The following example uses the _framesloaded property to start a SWF file when all the frames are loaded If all the frames aren’t loaded, the _xscale property of the movie clip instance loader is increased proportionally to create a progress bar Enter the following ActionScript in Frame 1 of the Timeline: var pctLoaded:Number... following example disables the circle_mc movie clip when the user clicks it circle_mc.onRelease = function() { trace("disabling the "+this._name+" movie clip."); this.enabled = false; }; 512 Chapter 2: ActionScriptLanguage Reference MovieClip.endFill() Availability Flash Player 6 Usage my_mc.endFill() : Void Parameters None Returns Nothing Description Method; applies a fill to the lines and curves added since... these methods already contains a movie clip For more information, see “Managing movie clip depths” in Using ActionScript in Flash 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 example displays the depth occupied by the logo_mc movie clip... nielsen/spotlight_jnielsen.jpg"); trace(this.getInstanceAtDepth(1)); // output: _level0.logo_mc See also MovieClip.getDepth(), MovieClip.getNextHighestDepth(), MovieClip.swapDepths() 522 Chapter 2: ActionScriptLanguage Reference MovieClip.getNextHighestDepth() Availability Flash Player 7 Usage my_mc.getNextHighestDepth() : Number Parameters None Returns An integer that reflects the next available depth... (that is, negative numbers are not returned) For more information, see “Managing movie clip depths” in Using ActionScript in Flash 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 example creates a new movie clip instance, logo_mc, at the next . lineTo(600, 510); lineTo(600, 310); lineTo(100, 310); 502 Chapter 2: ActionScript Language Reference endFill(); } See also MovieClip.beginFill(), MovieClip.endFill(),. 2004/Samples/HelpExamples/ See also MovieClip.lineStyle() 504 Chapter 2: ActionScript Language Reference MovieClip.createEmptyMovieClip() Availability Flash