Flash Vista - Home
Newest Cool Site
The Two Tales
Site info | Archive
Main Navigation
Home
New Links
Top Rated
Most Popular
Cool Sites
Search

Flash Tutorials
Flash Resources
Flash News
Flash Templates
Flash Intro Templates
Website Templates
Flash Games
Flash Books
FlashVista Polls
Sitemap


Random Link
Czech
Oxygen Electronics
Site info | Get another
FlashVista
Login
Register
Subscribe

Add Link
Modify Link
Favorites
Suggest Category

Advertise with us
Support us
Credits / Thanks
Contact

Flash Templates:

More Templates ...

Mailing List
User

Password



Register
Forgot password?
Partner websites
iPhone cases and accessories
Free Seo Tools
Free Tutorials
Free Video Tutorials
Best Free Scripts
Wii Fit
Wii Fit News
Other Resources
Suggest
Suggest this site to a friend


Mailing List
Status: Not logged in

English English German French Spanish Italian Portuguese Russian Polish Finnish Dutch Swedish Thai Romanian Traditional Chinese Simplified Chinese
SearchNot logged in
Keyword: Search for: Advanced Search


Don't worry about depths anymore


NEW Flash Tutorials in Video Format - Powered by LearnFlash.com: 45 minutes of flash tutorials now available in streaming format or download. Topics Include flash for beginners, text effects, actionscripting, audio/video, flash 8 and more.


Download the source file for this tutorial Printer version



by Mirza Hatipovic

In this example i will extend the MovieClip class and create custom methods similar to createEmptyMovieClip, createTextField and attachMovie. The difference is that you don't have to worry about the depth, you only need to provide the instance name. The new methods are the following:


easyCreateEmptyMovieClip(instanceName);
easyCreateTextField(instanceName);
easyAttachMovie(identifier, instanceName, [init_obj]);


First we add the easyCreateEmptyMovieClip method. Note that all the code will be placed on the first frame of a blank layer. Here's the code for the first method:


MovieClip.prototype.easyCreateEmptyMovieClip = function(instance_name) {
var depth_count = 0;
for (var clip in this) {
if (typeof this[clip] == "movieclip" || this[clip] instanceof TextField) {
if (this[clip].getDepth()>0) {
depth_count++;
}
}
}
return this.createEmptyMovieClip(instance_name, ++depth_count);
};


Just like the «original» method, the method returns the reference to the newly created clip.

Now on to the easyCreateTextField method:

MovieClip.prototype.easyCreateTextField = function(instance_name, x, y, width, height) {
var depth_count = 0;
for (var clip in this) {
if (typeof this[clip] == "movieclip" || this[clip] instanceof TextField) {
if (this[clip].getDepth()>0) {
depth_count++;
}
}
}
return this.createTextField(instance_name, ++depth_count, x, y, width, height);
};


The final method is the easyAttachMovie method:


MovieClip.prototype.easyAttachMovie = function(identifier, instance_name, init_obj) {
var depth_count = 0;
for (var clip in this) {
if (typeof this[clip] == "movieclip" || this[clip] instanceof TextField) {
if (this[clip].getDepth()>0) {
depth_count++;
}
}
}
if (arguments.length == 3) {
return this.attachMovie(identifier, instance_name, ++depth_count, init_obj);
} else {
return this.attachMovie(identifier, instance_name, ++depth_count);
}
};


Just like the built-in attachMovie method, the method accepts an optional third argument (initObj).

Here are some code examples:


//create empty movie clips and don't worry about the depth
_root.easyCreateEmptyMovieClip("line1_mc");
line1_mc.moveTo(100, 100);
line1_mc.lineStyle(1, 0x000000, 100);
line1_mc.lineTo(200, 50);
//second clip
_root.easyCreateEmptyMovieClip("line2_mc");
line2_mc.moveTo(200, 200);
line2_mc.lineStyle(1, 0xff0000, 100);
line2_mc.lineTo(200, 50);
//third clip
_root.easyCreateEmptyMovieClip("line3_mc");
line3_mc.moveTo(300, 300);
line3_mc.lineStyle(1, 0xffff00, 100);
line3_mc.lineTo(200, 50);
//create a textfield and don't worry about the depth of the previous mc's
_root.easyCreateTextField("message_txt", 200, 200, 200, 50);
message_txt.border = true;
message_txt.text = "hi";
//same for attachMovie without providing the depth
_root.easyAttachMovie("circle", "circle1_mc");
_root.easyAttachMovie("circle", "circle2_mc");
circle2_mc._x = 200;


Please download the source .fla code and study the provided example code.


(Added: 11-04-2003, Hits: 2, Rating: 4.00, Votes: 12, Reviews: 0)
Add to Favorites Suggest to a Friend

Reviews: (0)


Add Review
Please note:
We review EVERY comment before it appears on the site, so please dont waste your time by posting spam links :)
No URLs allowed, no HTML please.

If you register or login first, your review will contain your nickname


Rate It



Excellent!
Very Good
Good
Fair
Poor