Developing Webs logo
Google
Web DW-Main DW-Photoshop
Visit the message board for solutions or post a question Check out the Classes offered for free at Developing Webs Voice Chat submit a tutorial, resources, article, font for publication consideration and earn a one way link back to your site Get more specifics about the Developing Webs Voice chat room and its room members View the current news at Developing Webs alternative sites which are resources for your d3evelopment needs Join Developing Webs Chat Link to us on your web page to help support this resource! Check out Developing Webs At yahoo groups! Developing Webs Home Adobe Photoshop Tutorials Macromedia Flash Tutorials Jasc Paint Shop Pro Tutorials Adobe Illustrator Animation basics Some Basic PHP tutorials Perl Tutorials HTML Tutorials Cascading Style Sheets javascript Front Page Tutorials Macromedia Dream Weaver Tutorials dreamweaver Publishing your site, FTP, ChMod, Promotions Tools to help you create your site Free and shareware fonts to download Photographs to use in your projects Shop for your site needs Free Online classes REcommend this site to others Log in or edit your information when logged in Developingwebs Log Out Change My Account details and preferences
RSS Newsfeed
for your site
DW News
Calendar
DW Forum
Right click on button and copy shortcut

Add to My Yahoo!

Reminder
Remember to book mark this site!



Request a Tutorial

Using the If...else statement to set movie clip properties.

Download the FLA to look at the coding

Conditional statements are important to advanced action scripting. This is a simple tutorial, to introduce you to the conditional statement using the properties _visible, _alpha, _xscale, _height, rotation, _x.

 

 

1. Create the graphics

  • Create a new movie.
  • Create your buttons.
    • Using the rectangle tool, create a square in frame 1 on layer 1.
    • Convert to a symbol called button, with the properties of a BUTTON.
    • Place a total of six buttons on your stage as shown in the example.
  • Create your object you will manipulate the properties of.
    • Use the oval tool and create a circle on the stage.
    • Convert this circle to a symbol called circle with the properties of a MOVIE clip.
    • Open your instance panel and name the instance of your circle cir1
    • Make sure this circle is behind all the buttons by highlighting the circle and select modify => arrange => send to back

2. Script Visibility. The visibility has two different values. 0 (zero) is invisible, and 1 is visible. Our visibility state will read like this:

When you click the button,
If the movie clip is invisible then set it to visible.
...Otherwise set it to invisible.

Here is how you do it.

  • Click on the top button.
  • Open your scripts panel.
  • Click the  + => actions => if. This will write the first part of the condition statement. You will then have to write the condition which you are testing.
  • In the blank below on the actions panel type in the statement _root.cir1._visible == 0
    This tests the instance cir1,
    • which has the pathway _root.cir1
    •  for the property _visible
    • where 0 means false (invisible)
    • == is a double equal sign used to test equations, not set variables.
  • Click + => actions => Set variable. This will allow us to set the action to follow if the condition is true.
    • Type in the variable as the pathway to the clip,
    • period (.)
    • the property (_visible)
    • type in the value 0 in the value box
    • Check expression box for value.
  • Click + => actions => Else . This will be the alternative if the IF statement is not true. 
  • Click + => Actions => Set Variable
    • Type in the pathway to the clip,
    • period
    • the property that you are setting
    • set the value as 1 in the Value box
    • Check expression box for value.

Your script should look like this:

 

3. Set the Transparency or _alpha value of a movie clip. The _alpha value ranges from 0 (zero) to 100 percent.. 0 (zero) is totally transparent, 100 is totally opaque. Our visibility state will read like this:

When you click the button,
If the movie clip is Opaque then set it to 50% transparency.
...Otherwise set it to Opaque.

Here is how you do it.

  • Click on the second button.
  • Open your scripts panel.
  • Click the  + => actions => if. This will write the first part of the condition statement. You will then have to write the condition which you are testing.
  • In the blank below on the actions panel type in the statement _root.cir1._alpha == 100
    This tests the instance cir1,
    • which has the pathway _root.cir1
    •  for the property _visible
    • where 100 means opaque.
    • == is a double equal sign used to test equations, not set variables.
  • Click + => actions => Set variable. This will allow us to set the action to follow if the condition is true.
    • Type in the variable as the pathway to the clip,
    • period (.)
    • the property (_alpha)
    • type in the value 50 in the value box
    • Check expression box for value.
  • Click + => actions => Else . This will be the alternative if the IF statement is not true. 
  • Click + => Actions => Set Variable
    • Type in the pathway to the clip,
    • period
    • the property that you are setting (_alpha)
    • set the value as 100 in the Value box
    • Check expression box for value.

Your script should look like this:

 

4. Scaling your Movie clip. The _xscale and _yscale adjust the size of your object on the X and y coordinated respectively. These values are based on a percentage of the original movie clip. A value of 50 for _xscale will reduce the movie clip to half its width. A value of 200 will increase the width of the image to twice its normal width. A value of 100 will be the exact width of the movie clip you created.

When you click the button,
If the movie clip is 100% wide then set it to 50% wide.
...Otherwise set it to 100% wide.

Here is how you do it.

  • Click on the top button.
  • Open your scripts panel.
  • Click the  + => actions => if. This will write the first part of the condition statement. You will then have to write the condition which you are testing.
  • In the blank below on the actions panel type in the statement _root.cir1._xscale == 100
    This tests the instance cir1,
    • which has the pathway _root.cir1
    •  for the property _xscale
    • where 100 means 100% or full size.
    • == is a double equal sign used to test equations, not set variables.
  • Click + => actions => Set variable. This will allow us to set the action to follow if the condition is true.
    • Type in the variable as the pathway to the clip,
    • period (.)
    • the property (_xscale)
    • type in the value 50 in the value box
    • Check expression box for value.
  • Click + => actions => Else . This will be the alternative if the IF statement is not true. 
  • Click + => Actions => Set Variable
    • Type in the pathway to the clip,
    • period
    • the property that you are setting
    • set the value as 100 in the Value box
    • Check expression box for value.

Your script for _xscale should look like this:

Now write the same script for _yscale. It should look like this:

5. Set the height and width of the Movie Clip.  The _height and _width of the movie clip is a measure in pixels. You can set these values, adjust these values during the movie using action script. Your button for height script may read like this:

When you click the button,
If the movie clip is  178.5 pixels high, then set it to 50 pixels high.
...Otherwise set it to set it back to 178.5 pixels.

Follow the direction like in 2, 3, and 4 and create buttons for _height and _width.

Your script for height should look like this:

 

Create a script for the next button that is for width of your ball.. Use the following criteria:

When you click the button,
If the movie clip is  178.5 pixels high, then set it to 80 pixels high.
...Otherwise set it to set it back to 178.5 pixels.


Your script for width should look like this:

 

6. Set the position of the Movie Clip.  The _x and _y coordinates of the movie clip determines where the movie clip will be located in reference to the upper left corner of the stage (0,0). You can set these values, adjust these values during the movie using action script.. Your button for the _x script may read like this:

When you click the button,
If the movie clip is  is 200 pixels from the left side, then set it to 50 pixels from the left.
...Otherwise set it to set it back to 200 pixels from the left.

Follow the direction like in 2, 3, and 4 and create buttons for _x values.
Your script for height should look like this:

 

Create a script for the next button that is for width of your ball.

When you click the button,
If the movie clip is  is 100 pixels from the Top of the stage, then set it to 50 pixels from the Top.
...Otherwise set it to set it back to 100 pixels from the top.

Your script for adjusting the _y value should look like this:

 

7. Rotating your Movie Clip.  Your movie clip can be rotated on its access via script You can set these values by simply referring to _rotation and set it to the number of degrees you would like it to rotate. rotation degrees are clockwise.

Your button for the _rotation script may read like this:

When you click the button,
If the movie clip is  oriented at 0 degrees rotation, then rotate it to 90 degrees..
...Otherwise set it to set it back to 0 degrees..

Follow the direction like in 2, 3, and 4 and create a button for _rotation..
Your script for rotation should look like this:

 



"Building The Web Into a Nicer Place -- One Site At A Time"
Developing Webs Group Copyright © 2001-2008 All Rights Reserved
Privacy and Legal