NIET
Would you like to react to this message? Create an account in a few clicks or log in to continue.
LATEST NEWS
HI FRIENDS...!








WELCOME TO NIET GALAXY








KEEP VISITING...!








IT IS FOR NIET STUDENTS
FOLLOW ME
ActionScript program for Scripting Mask Twit_05
NOTICE BOARD...!!!
Latest topics
» Beautiful Brides
ActionScript program for Scripting Mask EmptyMon Sep 14, 2009 12:07 pm by NIETGALAXY

» Bollywood actresses In Sarees
ActionScript program for Scripting Mask EmptyMon Sep 14, 2009 12:05 pm by NIETGALAXY

» Childhood photos of Bollywood stars
ActionScript program for Scripting Mask EmptyMon Sep 14, 2009 12:02 pm by NIETGALAXY

» How to Use the Secret
ActionScript program for Scripting Mask EmptySat Sep 05, 2009 1:35 pm by NIETGALAXY

» How to Be A Teacher's Pet
ActionScript program for Scripting Mask EmptySat Sep 05, 2009 1:28 pm by NIETGALAXY

» How to Get into the Habit of Studying for a Test
ActionScript program for Scripting Mask EmptySat Sep 05, 2009 1:24 pm by NIETGALAXY

» Vodafone Free GPRS hack
ActionScript program for Scripting Mask EmptyTue Aug 18, 2009 8:31 pm by anil kumar

» How To Get Big Arms?
ActionScript program for Scripting Mask EmptyTue Aug 18, 2009 8:24 pm by anil kumar

» Airtel GPRS hack
ActionScript program for Scripting Mask EmptyTue Aug 18, 2009 8:20 pm by anil kumar


ActionScript program for Scripting Mask

Go down

ActionScript program for Scripting Mask Empty ActionScript program for Scripting Mask

Post by NIETGALAXY Wed Jul 29, 2009 7:56 pm

Record 14: Scripting Mask
---------------------------------------------------------------------------
Problem
You want to create a mask at runtime.

Solution
Use the Drawing API to create a shape and then use MovicClip.setMask( ) to apply the mask.

Discussion
Masks can be used to create unique shapes or visual effects. For example, you can use masks to create wipes and transitions or interesting animations in which only the masked portion of the artwork is visible at a given time. You can even create masks that change shape over time, and use them to mask bitmapped graphics (in movie clips).

You can use any movie clip as a mask of another movie clip using the setMask( ) method. The setMask( ) method is called from the movie clip to be masked, and you should pass it a reference to the movie clip that acts as the mask:

maskedMovieClip.setMask(maskMovieClip);
In most cases, masks are simple shapes, such as rectangles or circles. You do not need to use the Drawing API to draw the mask movie clip, but it is recommended that you do so unless the mask is of an unusual shape.

First, here is an example in which a mask follows the mouse. The mask is assigned to a movie clip containing a loaded image, so the effect is that the user can see only the portion of the image over which he has positioned the mouse.

// Include the drawing methods, which are needed for the drawCircle( ) method.
#include "DrawingMethods.as"

// Create a movie clip and a nested movie clip for loading an image. See Recipe 15.3
// for more information on the need for creating nested movie clips when loading
// external JPEGs.
_root.createEmptyMovieClip("image_mc", 1);
_root.image_mc.createEmptyMovieClip("imageHolder_mc", 1);

// Load the image into the movie clip. You can use this URL if you want, but it will
// work only while you are using the test or standalone players.

// for more information on loading JPEGs.
image_mc.imageHolder_mc.loadMovie("http://www.person13.com/ascb/images/image1.jpg");

// Draw the masking movie clip.
_root.createEmptyMovieClip("mask_mc", 2);
mask_mc.lineStyle(3, 0x000000, 0);
mask_mc.beginFill(0, 100);
mask_mc.drawCircle(60);
mask_mc.endFill( );

// Call the setMask( ) method on the masked movie clip and pass it the masking movie
// clip as a parameter.
image_mc.setMask(mask_mc);

// Call the startDrag( ) method of the masking movie clip so that the mask can be
// moved with the cursor.
mask_mc.startDrag(true);
Next, here is an example in which a mask is used to create a wipe transition between two loaded images.

#include "DrawingMethods.as"

// Create a movie clip and a nested movie clip and load the first image into it.
_root.createEmptyMovieClip("image0_mc", 1);
_root.image0_mc.createEmptyMovieClip("imageHolder_mc", 1);
image0_mc.imageHolder_mc.loadMovie("http://www.person13.com/ascb/images/image1.jpg");

// Create another movie clip and nested movie clip and load the second image into it.
// Both image0_mc and image1_mc are created at (0,0). This means that they will
// overlap. This is what we want.
_root.createEmptyMovieClip("image1_mc", 2);
_root.image1_mc.createEmptyMovieClip("imageHolder_mc", 1);
image1_mc.imageHolder_mc.loadMovie("http://www.person13.com/ascb/images/image2.jpg");


// Draw the masking movie clip. The dimensions of the images are 640 x 480 (if you
// load the images using the URLs provided) and so the mask should be a rectangle
// with the same dimensions.
_root.createEmptyMovieClip("mask_mc", 3);
mask_mc.lineStyle(3, 0x000000, 0);
mask_mc.beginFill(0, 100);
mask_mc.drawRectangle(640, 480);
mask_mc.endFill( );

// Position the mask so that it is off to the left side of the Stage.
mask_mc._x = -320;
mask_mc._y = 240;

// Call the setMask( ) method to set mask_mc as the mask for image1_mc. This causes
// image0_mc to display initially, even though it is below image1_mc.
image1_mc.setMask(mask_mc);

// Define an event handler method for image0_mc so that the mask movie clip moves
// when the user clicks on image0_mc.
image0_mc.onRelease = function ( ) {

// Use an onEnterFrame( ) event handler method to move the mask. This assumes you
// have the default frames per second setting of 12.
_root.mask_mc.onEnterFrame = function ( ) {

// Move the mask to the right by 12 pixels.
this._x += 12;

// If the mask is fully masking the image, then delete the onEnterFrame( ) method.
if (this._x >= 320) {
this._x = 320;
delete this.onEnterFrame;
}
}
}

---------------------------------------------------------------------------
Program
---------------------------------------------------------------------------
var m:Object=new Object();
m.onLoadInit=function(target_mc:MovieClip)
{
target_mc._visible=false;
target_mc._x=(Stage.width-target_mc._width)/2;
target_mc._y=(Stage.height-target_mc._height)/2;
var mask:MovieClip=target_mc.createEmptyMovieClip("mask_mc",20);
with(mask)
{
beginFill(0xFF00FF,100);
moveTo(0,0);
lineTo(target_mc._width,0);
lineTo(target_mc._width,target_mc._height);
lineTo(0,target_mc._height);
lineTo(0,0);
endFill();
}
target_mc.setMask(mask);
target_mc._visible=true;
}
var mask_tween:Object=new Tween(mask,"_ysacle",0,100,2,true);
this.createEmptyMovieClip("img_mc",10);
var i:MovieClipLoader=new MovieClipLoader();
i.addListener(m);
i.loadClip("Sunset.jpg",img_mc);
NIETGALAXY
NIETGALAXY
Admin

Posts : 401
Join date : 2009-07-03
Location : GUNTUR

https://niethangout.forumotion.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum