Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Design > Adobe Creative Suite

This chapter is from the book

Creating the Function for X and Y Movement

This function is basically the same as your previous function, except you specify a target X position and a target Y position for the movement. This means you can move panels diagonally as well as up and down or left and right. The X and Y target positions are defined as new parameters in your function definition as follows:

function movePanel(x,y,whichClip,baseRate)

When you call the function, you set the X and Y positions to where you want to move the panel as follows:

function movePanel(100,300,this._name,1.6)

Before, the panel headed towards the X position of the mouse, this time it moves towards the value of X and Y.

The full function follows. The Y movement is the same as the X movement, only this time you alter the _y property. Add the following code to the Script window:

function movePanel(x,y,whichClip,baseRate) {
         if (_root[whichClip]._x > x) {
                difference = _root[whichClip]._x - x;
                rate = difference / baseRate;
                _root[whichClip]._x = _root[whichClip]._x - rate;
          }
          if (_root[whichClip]._x < x ) {
                 difference = x - _root[whichClip]._x;
                 rate = difference / baseRate;
                 _root[whichClip]._x = _root[whichClip]._x + rate;
          }
          if (_root[whichClip]._y > y) {
                difference = _root[whichClip]._y - y;
                rate = difference / baseRate;
                _root[whichClip]._y = _root[whichClip]._y - rate;
         }
         if (_root[whichClip]._y < y ) {
               difference = y - _root[whichClip]._y;
               rate = difference / baseRate;
               _root[whichClip]._y = _root[whichClip]._y + rate;
          }
}

Calling the Function

You need to create a script loop that constantly calls the function and moves the panels into their target positions when a button is clicked. You could do this with a conventional movie clip script loop, but instead you'll do what you did in the previous example and use an onClipEvent handler on the pictures movie clip itself:

  1. Select the pictures movie clip. Use the Instance panel to name it pictures1.

  2. With this movie clip still selected, press Ctrl+Alt+A (Cmd+Opt+A on Mac) to display the Object Actions panel for this movie clip. You can add the onClipEvent(enterFrame) handler in this Script window.

  3. The main point of this script is to loop around and call the function each time so that it moves the panel to its target destination. But you only want it to do this when a button is clicked. Because of this you are going to use a variable of type boolean. This type of variable can only be set to true or false. When you click a button, you will set a variable called pressed to true. If this variable is true, you know you need to move the panel.

    if (_root.pressed == true) {

    Accordingly, call the function as follows:

    _root.movePanel(_root.targetx,_root.targety,this._name,1.5);

    The full script for this is as follows:

    onClipEvent(enterFrame) {
            if (_root.pressed == true) {
            _root.movePanel(_root.targetx,_root.targety,this 
    ._name,1.5);
                  }
      }

    Your code should look like Figure 3.24.

    Figure 3.24. This is the code you will need to begin to call the functions.

Notice that when you call the function, you don't actually specify the target X or Y position. You tell it to use the values of two variables—targetX and targetY. These variables are set on the main timeline when a button is clicked, so you can easily alter the destination of the panels with the ActionScript you attach to the buttons.

Of course, you need to set the value of pressed to false when the movie first starts; otherwise, the panels will start to move immediately, rather than waiting for a button click. To set it to false, open the script in the functions layer and add this line of code above the function:

_root.pressed = false;

Triggering the Function with a Button

  1. Create a new layer and name it buttons.

  2. Draw a small box on the stage in this layer (see Figure 3.25).

  3. Figure 3.25. Buttons can be programmed to call a variety of functions, including multiple functions with a single click.

  4. Select this box and turn it into a button by pressing F8 and choosing the Button radio button. Name it button. Click OK.

    When this button is clicked, it needs to do three things. First, it must set the value of the targetx variable. If you don't actually want to move it across the X-axis, you can simply tell it to stay put by using the panel's current X position as follows:

    _root.targetx = pictures1._x;

    Next, set the value of the targetY position as follows:

    _root.targety = 0;

    Finally, set the value of pressed to true as follows, causing the function to kick in:

    _root.pressed = true;

    This all needs to go in an on(release) event handler. To do this, select the button and press Ctrl+Alt+A (Cmd+Opt+A on Mac) to display the Object Actions panel for this button. Add the following script:

  5. on (release) {
              _root.targetx = pictures1._x;
                _root.targety = 0;
               _root.pressed = true;
     }

Setting Up the Masks

So far you've created a movie clip with your pictures in it, created the main function, and made a button to move the panel. For your transition effect to work, you need to have two identical panels—the second moving slightly more slowly than the first.

  1. Select the pictures1 movie clip and copy it (Ctrl+C [Cmd+C on Mac]).

  2. Underneath the layer with the pictures1 movie clip on it, create a new layer and name it pictures2. (see Figure 3.26).

  3. Figure 3.26. Make sure this layer is underneath the pictures1 layer.

  4. Paste the copied movie clip into this layer (Ctrl+Shift+V [Cmd+Shift+V on Mac]). You now have the second copy of the pictures movie clip in place. You might want to turn off the visibility for the pictures1 layer for the time being so you can just see this new clip (see Figure 3.27).

  5. Figure 3.27. Turn off the visibility of the pictures1 layer to see the layer underneath, or alternatively turn that layer into an outline.

  6. With this new, copied panel selected, rename it in the Instance panel as pictures2. Each clip should have its own name so that it doesn't confuse the script.

  7. Now that you have the second panel in place, you need it to move more slowly than the first panel. All you have to do is alter the movePanel function call attached to this clip.

  8. With the clip still selected, press Ctrl+Alt+A (Cmd+Opt+A on Mac) to display the Object Actions panel. You should see that it already has an enterFrame event handler attached to it. This is because this clip is a copy of the original.

  9. To slow this clip down, increase the number at the end of the function call. Remember, the higher the number, the more slowly the panel moves. The original was set to 1.5, so set this to 2 (see Figure 3.28).

    Figure 3.28. Play around with these numbers to alter the speed of the effect.

Creating the Mask Shapes

You next need to create the actual mask shapes for the two picture layers. Remember that the two masks must form a whole when shown together. Other than that, they can be any shape you desire.

  1. Create a new layer above the pictures1 layer and name it mask1. You will create the first of the two masks on this layer.

  2. Draw a rectangle on this layer. Use the Info panel to make the rectangle 225x40 (see Figure 3.29).

  3. Figure 3.29. The rectangle you create here begins the mask creation.

  4. With this rectangle still selected, use the Align panel to align it to the upper edge and center it on the stage (see Figure 3.30).

  5. Figure 3.30. After the rectangle is aligned on the stage, you then begin the replication.

    This shape needs to be copied four times, with each of the five blocks spaced evenly across the vertical space of the stage.

  6. With the rectangle selected, copy it (Ctrl+C [Cmd+C on Mac]).

  7. Paste it in place (Ctrl+Shift+V [Cmd+Shift+V on Mac]).

  8. Without deselecting this new rectangle, use the arrow keys to move it underneath the original (see Figure 3.31).

  9. Figure 3.31. If your alignment matches this figure, you're ready to copy and space the new rectangles.

    Repeat this procedure for this new rectangle until you have five rectangles spread out across the stage from top to bottom. Align the lower-most rectangle so it's at the bottom of the picture. You'll want to space them evenly across the stage. To do this, select all the rectangles. The best way to do this is to lock all the other layers and press Ctrl+A (Cmd+A on Mac) to select all the objects in the mask1 layer. Now use the Align panel and make sure the To Stage option is depressed. Click the Distribute Vertical Center button, and the rectangles will be spaced evenly in the vertical direction (see Figure 3.32).

    Figure 3.32. Make sure the To Stage button is depressed.

  10. To turn this layer into a mask for the pictures1 layer underneath, first deselect all the panels on the mask layer by pressing Ctrl+Shift+A (Cmd+Shift+A on Mac).

  11. Right-click (Ctrl+click on Mac) the mask1 layer name and choose Mask from the popup (see Figure 3.33).

  12. Figure 3.33. After you have masked off the picture...

    The picture on the pictures1 layer is now masked off, with the only areas showing through now being the areas defined by the rectangles. To see the mask effect, turn off the visibility of the pictures2 layer (see Figure 3.34).

    Figure 3.34.  ...you can evaluate the mask effect.

    You also need the pictures2 layer to be masked in exactly the same way, but its mask should be the opposite of the pictures1 mask. That is, to the point where you can't see the image in pictures1; you should be able to see the image in pictures2.

  13. Unlock the mask1 layer, and select all five rectangles and copy them (Ctrl+C [Cmd+C on Mac]).

  14. Lock that layer again to turn the mask back on. Above the pictures2 layer, add a new layer and name it mask2.

  15. Paste the copy (Ctrl+Shift+V [Cmd+Shift+V on Mac]) of the five rectangles into this layer. You won't see them appear, however, because they will be covered by the pictures1 layer above them.

  16. Use the arrow keys to move all five rectangles down so you can see them (see Figure 3.35).
  17. Figure 3.35. If you now are looking at all five rectangles, creating the mask is simple.

  18. Finally, turn this layer into a mask for the pictures2 layer by repeating Steps 7 and 8.

Adding the Final Button

Now you have your two movie clips masked off with alternate masks, and you have a button in place to move the strip upward. What you need now is a button to move the strip back down again.

  1. In the button layer, select the small button, copy it (Ctrl+C [Cmd+C on Mac]), and then paste it in place (Ctrl+Shift+V [Cmd+Shift+V on Mac]).

  2. Use the arrow keys to move it below the original button (see Figure 3.36).

  3. Figure 3.36. Building the down button is the final step.

  4. With this new button still selected, press Ctrl+Alt+A (Cmd+Opt+A on Mac) to open the Object Actions panel.

  5. In the on(release) script, change the targetY position value to 300. This means that when this button is clicked, the panel is moved so that its Y position will equal 300. The full code for the button is as follows:

  6. on (release) {
            _root.targetx = pictures1._x;
            _root.targety = 300;
            _root.pressed = true;
     }
  7. Now test the movie. Click on the top button and the panel will slide upwards, giving a venetian blind type transition effect. Click the bottom button and it slides back to its original position (see Figure 3.37).

  8. Figure 3.37. If your code is in place, you should be able to move the panels up or down.

Peachpit Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from Peachpit and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about Peachpit products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites; develop new products and services; conduct educational research; and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email ask@peachpit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by Adobe Press. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.peachpit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020