You can reduce the amount of animation you need to do when you use certain actionscripting commands. Here we will references different properties of our objects.Here are a couple examples:
Example 1:
Create a button. Place it on the main stage.
Create two movie clips with a graphic in each. Drag these both to the main stage. Name them in the Instance panel. I will name mine: blob1 and blob2
Now click on your button. Then click on the actionscript arrow at the bottom of your stage.
At the left of your actionscript window there is an arrow. When you select this arrow you can go between Normal and Expert Mode.
Select Expert Mode.
Now you can type in your code. Here it is:
on (release) {
// move blob1 to the right and down
blob1._x = 400;
blob1._y = 300;
// move blob2 to the left
blob2._x = 0;
blob2._width = 800;
Once you have added your code you can test your button.
Try changing the values and also the parameters. What if you change the alpha?
Example 2:
You can also add scripts to MovieClips and not just to buttons. Here is an example:
Create a new MovieClip.
Inside this clip create a character or thing that you want to move across the stage. C
Create keyframes for this thing on Frame 1 and 2.
Add actionscript to frame one. Highlight frame one or double click on it. Add the following code:
_x = _x + 10;
_y = _y + 2;
**Notice that you do not need to use an instance name because it refers to this movieclip itself.
Now add the following code to frame 2:
gotoAndPlay (1);
*This allows it to be an animated object rather than a static one.
Now go to the main stage and drag your movieclip on it. Use as many as you like. And test!
Example 3:
You can also add sript to frames.
Make a movieclip. Drag it onto your stage. Name its Instance. I have named mine blob1 and blob2.
Highlight your frame and add the following code:
blob1._x = blob1._x + 10;
blob2._x = blob2._x + 10;
This is going to make my instances move across the stage at 10 increments at a time.
Make sure you have a frame (without a keyframe) on frame 2. This will make it an animated action.
Example 4:
You can also have these change in increments.
Create a button.
Create a movieclip. Name your movieclip. I named mine hori
On the button add the following code:
on (release) {
hori._x = hori._x + 20;
hori._height = hori._height + 10;
hori._alpha += -5;
This code is moving my movieclip horizontally 20 pixels to the right and then adding 10 pixels to the height while also subracting alpha (thereby fading my movieclip out).
Blur transition effect
Written by: Patrick Mineault
Actionscript.org
I'm sure you've seen this effect a thousand times: a blurry picture becomes
sharp or vice versa on rollover. Here's an example:
The effect seems complicated and it looks fancy but it's incredibly simple.
I've chosen to use actionscript and not tweens for the animation in this tutorial,
so this should give you a hint for other projects involving properties.
Creating the assets
You'll need a picture of some kind. Flash doesn't have a function for blurring
so we'll do this in PS. Open a copy of your picture and apply a gaussian blur
filter to it. Save it as a jpg file.
Import both the original and the blurred image into Flash. Create a new empty
movieclip called 'assembled' (Ctrl+F8). Create two layers in it. Place the blurry
picture on the bottom layer and the original on top. Select the original picture
and convert it to a movie clip (F8). Give this movieclip an instance name of
'original'. Don't confuse the movieclip name with the instance name. The instance
name is what you enter in this panel:
Adding the script
The script will manipulate the original photo's transparency. Go into the main
timeline and place an instance of the 'assembled' movieclip. Keep the movieclip
selected and go into the actions panel. Enter this script:
onClipEvent(load)
{
dir = 0;
speed = 6;
original._alpha = 0
this.onRollOver = function()
{
dir = 1;
}
this.onRollOut = function()
{
dir = -1;
}
useHandCursor = false;
}
onClipEvent(enterFrame)
{
temp = original._alpha + speed*dir;
original._alpha = Math.min(100,Math.max(temp,0));
}
Press Ctrl+enter to test your movie. You should have get a blur transition
effect when you move your mouse over the photo. If you receive an error such
as: 'Clip events are permitted only for movie clip instances', it's because
you placed the script on a frame instead of on the movieclip. Make sure you
have the movieclip selected before pasting the script into the actions panel.
Let's see how this works. We have two variables that are set up when the movieclip
is loaded: dir and speed. Dir is set to 1, -1 or 0 depending on whether we want
the animation to move forward, backward or to stay still. When we rollover or
rollout of the movieclip, the direction of the animation is reversed.
On each frame the script calculates a new tentative transparency value for the
<original picture. The nested Math.min and Math.max functions bound the value
of the temp variable to between 0 and 100; this is crucial as these are the
only reasonable values for the _alpha property. So all the script does is make
the original picture opaque on rollover and clear on rollout. That's all there
is to it.
Final thoughts
You can try different filters for the blurred picture instead of gaussian blur.
In particular, motion blur and radial blur will give interesting effects.
It may be a good idea to make the blurred picture duotone or grayscale for effect.
If you want the animation to be triggered by another element on stage, the key
is to assign the onRollOver and onRollOut actions to another button or movieclip.
For example, for a button with an instance name of trigBtn placed on the _root
timeline, you would change this.onRollOver to _root.trigBtn.onRollOver and this.onRollOut
to _root.trigBtn.onRollOut.
You can adjust the speed of the animation by modifying the value of the speed
variable.