TARGETING MOVIE CLIP INSTANCES


When you drag a movie clip instance into a timeline and assign it an instance name, that name (as well as the clip's relationship to other timelines) determines its target path. Say, for example, you placed a movie clip instance on the main timeline and gave it an instance name of alien. That movie clip instance's absolute target path would be as follows:

 _root.alien 

As the movie's absolute target path, you can use the above in a script in any timeline of your project to communicate with this particular instance.

However, to target that instance from the main timeline, since it's a child movie of the main timeline, you could use the following relative path:

 alien 

If you were to place this same movie clip instance inside another movie clip instance named spaceship, which resided on the root timeline, the absolute target path would become the following:

 _root.spaceship.alien 

Since the relationship between the root timeline and the alien movie clip instance has changed, the root timeline must now use the following relative path to target it:

 spaceship.alien 

In addition, because the spaceship movie clip instance is now in the same position relative to the alien movie clip instance as the root timeline was before, the spaceship instance can now target the alien movie clip instance as follows:

 alien 

In the following exercise, you will target specific movie clips based on their names and positions relative to the timeline that contains the script.

  1. Open movieclipTarget1.fla in the Lesson03/Assets folder. This file picks up where we left off in the last exercise. We will name the various instances on the stage so that we can target them in a script.

  2. With Property inspector open, select each instance on the stage and name it according to the value that the instance assigns to words when it loads.

    For example, if the selected instance were to set the value of words to "I'm Derek" on loading, you would name this instance Derek . Do the same for the other instances on the stage.

    graphics/03fig12.gif

  3. Double-click one of the instances to edit it in place. Inside this timeline is an instance of the Hatfield Child movie clip. With the Property inspector open, select the instance and name it myKid. Return to the main timeline.

    There are now six movie clip instances that you can target from any other timeline. Their absolute target paths are as follows:

     _root.Derek  _root.Derek.myKid  _root.Kathy  _root.Kathy.myKid  _root.Ashlie  _root.Ashlie.myKid 
  4. With the Actions panel open, select the instance named Kathy and add the following script at the end of the current script (where it reads this._rotation = this._rotation + .5;) :

     myKid._rotation = myKid._rotation + 20;  _root.Derek.myKid._xscale = _root.Derek.myKid._xscale + .5;  _root.Derek.myKid._yscale = _root.Derek.myKid._yscale + .5;  _root.Ashlie.myKid._y = _root.Ashlie.myKid._y - .5; 

    graphics/03fig13.gif

    The placement of these lines of script dictates that they be triggered with each mouse movement. Since this script is attached to the instance named Kathy, the first action uses a relative target path to target the myKid instance within itself. It sets the rotation property of this instance to its current value plus 20 every time the mouse is moved. The next two actions use absolute target paths to target the myKid instance inside the Derek instance. These actions will cause that instance to grow by .5 percent each time the mouse is moved. The last action uses an absolute target path to target the myKid instance inside the Ashlie instance. Each time the mouse is moved, the instance will move .5 pixels up from its current position.

  5. Choose Control > Test Movie to test the project.

    As you move the mouse, the myKid movie clip instances we targeted should perform the actions we scripted for them.

  6. Close the test movie to return to the authoring environment. Save your file as movieclipTarget2.fla.

    This completes this exercise as well as our use of this file in this lesson.



Macromedia Flash MX ActionScripting Advanced. Training from the Source
Macromedia Flash MX ActionScripting: Advanced Training from the Source
ISBN: 0201770229
EAN: 2147483647
Year: 2002
Pages: 161

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net