MovieClip.clear( ) Method | Flash 6 |
erases all Drawing API content from a movie clip |
The clear( ) method erases all lines (strokes) and shapes (fills) created with the MovieClip Drawing API methods in mc, but it does not affect content created in the Flash authoring tool. It also clears the current line style (as if lineStyle(undefined) were called) and returns the drawing pen to position (0,0). To activate lines for subsequent drawings, call lineStyle( ) before invoking any drawing methods.
You can't erase author-time content using the Drawing API. Instead, use the _visible property to hide a movie clip.
The following code draws a single line with a random line style on every frame. It uses clear( ) to erase the line drawn in the previous frame:
// A custom function to return a random integer Math.randomInt = function (minVal, maxVal) { r = Math.random(); return minVal + Math.floor(r * (maxVal + 1 - minVal)); } this.createEmptyMovieClip("drawing_mc", 1); drawing_mc.onEnterFrame = function () { this.clear(); this.lineStyle(Math.randomInt(1, 40), Math.randomInt(1, 0xFFFFFF)); this.moveTo(Math.randomInt(1, 550),Math.randomInt(1, 400)); this.lineTo(Math.randomInt(1, 550),Math.randomInt(1, 400)); }
Reader Exercise 1: Try removing the call to clear( ) to see how calls to the drawing functions are cumulative until clear( ) is invoked.
Reader Exercise 2: Using clear( ) erases the Drawing API content from the specified clip only. Write a custom function to erase all Drawing API content from all movie clips, starting with the specified clip and recursively erasing the dynamic content from any nested clips. Use a for-in loop to detect nested clips. You can use your function with the main timeline to erase all dynamic content.
MovieClip.beginFill( ), MovieClip.beginGradientFill( ), MovieClip.curveTo( ), MovieClip.endFill( ), MovieClip.lineStyle( ), MovieClip.lineTo( ), MovieClip.moveTo( ), MovieClip._visible; Chapter 13