Welcome to Dream.In.Code
Getting Help is Easy!

Join 132,165 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,674 people online right now. Registration is fast and FREE... Join Now!




AS 2.0 Basics 3 - MovieClips

 
Reply to this topicStart new topic

> AS 2.0 Basics 3 - MovieClips, [Flash 8]

BetaWar
Group Icon



post 18 Jul, 2008 - 08:05 PM
Post #1


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.

[b]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.

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:

CODE

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.
Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 11/21/08 02:35PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month