iNET Interactive - Online Advertising Agency
          
   Home    Authors    About    Login    Contact Us
   Search:   
Advanced Search     
  Articles

  ASP (26)
  ASP.NET (19)
  C and C++ (4)
  CFML (2)
  CGI and Perl (16)
  Flash (2)
  Java (7)
  JavaScript (28)
  PHP (92)
  MySQL (13)
  MSSQL (3)
  HTML (34)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

May 13, 2008
Rainbow Links
EarthWeb.com
 
May 13, 2008
MySpace Profile Page Resources
HTML Goodies
 
May 13, 2008
How to Upload Your Photos onto the Web
HTML Goodies
 
May 13, 2008
Email Marketing for MySpace Artists
HTML Goodies
 
May 13, 2008
Top Online Marketing Techniques
HTML Goodies
 
May 13, 2008
I want to create a site just like ____, is that a violation of...
About
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /Flash

Animate with Actionscript only 

  Views:    17978
  Votes:    16
by Mike Irving 11/03/04 Rating: 

Synopsis:

Use some simple actionscript to make movieclips move. No more frame by frame animations to tweek.
Pages: 
The Article

As a developer, I have run into situations where I wanted to make an object move, but its movement depended on other objects in the movie. A lot of times, this used to take forever; Building movie clip after movie clip with stop actions on certain frames. Well, by using onClipEvent scripts, this is much easier.

 

First, create a box just off the top of the stage. Press F8 to make it into a movieclip. Give it the instance name of my_box.

 

Now, create another, smaller box for a button. Press F8 to make it into a button.

 

Ok, Now, let’s make the first movieclip (my_box) ready to move. Click on the instance of my_box on the stage. Open the actions panel and enter the following code:

 

onClipEvent(load){

            // Set the variables up to be equal to where the clip is now.

            xDest = this._x;

            yDest = this._y

            aDest = this._alpha;

}

 

onClipEvent(enterframe){

            // See if the xDest has been changed

            if (this._x != xDest) {

                        this._x += (xDest-this._x)*.2;

            }

           

            // See if the yDest has been changed

            if (this._y != yDest) {

                        this._y += (yDest-this._y)*.2;

            }

           

            // See if the aDest has been changed

            if (this._alpha != aDest) {

                        this._alpha += (aDest-this._alpha)*.2;

            }

}

 

Ok, our box is ready to be moved. Now, let’s make the button do the moving. Click on the button you created and open the actions panel. In the panel, enter the following code:

 

on(release){

            _root.my_box.yDest = 100;

}

 

Ok, now save your file and test your movie. You will see that when you click the button, the box slides. You can also change the xDest to change the x coordinate or you can change the aDest which changes the alpha.

 

You can add other “Dest” variables to make the clip do more things like scale or rotate.

 

Also, notice the “*.2” part in the onClipEvent(enterframe) block. You can change this number to make the easing on the clip faster or slower. Play with it to make the movement the way you want it to look.

 

Also, duplicate the button on the stage, and change the code on it to be:

 

on(release){

            _root.my_box.yDest = -200;

}

 

Now, you can click one button to make the box slide down and another to make it slide up.

 

To download the flash movie for this tutorial, click here.

Pages: 



 
  Sponsors