Page 1 of 1

AS 2.0 Basics 3 - MovieClips [Flash 8] Rate Topic: -----

#1 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1134
  • View blog
  • Posts: 7,094
  • Joined: 07-September 06

Post icon  Posted 18 July 2008 - 09:05 PM

Instance Names[b/] why name a movieclip?
Instance Names are used to point actionscript code at a specific movieclip. For instance, if you have a movieclip on frame 1, layer 1 of _root and gave it an instance name of something like "holder" you could call to it from anywhere in your actionscript with _root.holder. Instance names become very important when making sites, games, apps, and other things with Flash and Actionscript.

Paths where the sidewalk ends
Paths can mean various things, in programming they are normally used for the "path" to a file or folder. For this tutorial we will be defining paths a bit differently. A path is the way to a movieclip from _root. If you had a movieclip called "holder" and inside of "holder" there was another movieclip called "btn" the path to "btn" would not be _root.btn but _root.holder.btn. Paths can also be taken from a relative point in the actionscript, which can make it easier and less cluttered. If you have the same movieclips as above, in the same positions and are editing the actionscript in "holder" you can call to "btn" by simply using something like so this.btn. this refers to the movieclip that is running the actionscript, in this case it is "holder". That would give the same result as _root.holder.btn, but you get to get rid of the _root.holder portion and just replace it with this.

[b]Looking at MovieClips

Movieclips can be created in a number of ways, but since this is ActionScript we will just look at how to create one with actionscript. Starting out you need to create a variable and have that variable represent a movieclip. This is accomplished like so:

var myMc:MovieClip = _root.createEmptyMovieClip("mc_01", 1);



The :MovieClip portion sets the variabel type as a MovieClip meaning that that variable will only accept movieclips and will raise an error if say a number was fed to it. It also allows for auto completion of functions and various calls for the movieclips. The createEmptyMovieClip function takes 2 parameters, the movieclip's Instance Name and its depth.

One important thing to realize is that you don't have to use the movieclips' instance name anymore to represent that movieclip. It now has a variable pointer, meaning that you can say myMc._y = 100; and it will be relayed to the movieclip "mc_01" which will position itself at (x, 100) where x is its _x value.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1