PDA

View Full Version : Using Base Classes on MovieClips


Blitz3000
03-14-2010, 04:16 AM
I know I'm a newb but here are the question:
1. Are custom base classes the way to go on movie clip symbols and is this standard practice when building Flash projects?
2. Can I still eventually make the base classes abstract enough to be reusable?

My questions above are regarding the difference between using a base class on a movie clip symbol or to add it via the document class and handling it elsewhere. The AS code and names i've used below are purely for the purpose of explaining the question. I've built a bunch of these simple menu/content presentations and am now wondering about the best practices of this task.

Previous to these questions I would normally make a movie clip and use the document class to add it, and then I'd manipulate it with another class. I would only ever use the Flash default MovieClip base class on the movie symbols in the library.

I recently built a simple AS3 Flash presentation with a menu and content like normal. After reading a forum thread I decided to build this one differently. I made two movie clips, 'menuMc' and 'contentMc' in the library as per usual, and linked a base class matching the names to each of them in linkage properties. I also added 'MainClass.as' as the document class in the fla properties. I then did something like this in the doc class:

import as.MenuMc;
import as.ContentMc;

private var _menuMc:MenuMc = new MenuMc();
private var _contentMc:ContentMc = new ContentMc();

addChild(_menuMc);
addChild(_contentMc);

This seemed to work a treat. In fact it was much easier to handle and I found I could even dispatch events from the movie clips timeline to it's base class.. very handy.. which left me with two questions. Are custom base classes the way to go on clips like these and is this standard practice when building Flash projects? and,can I still eventually make the base classes abstract enough to be reusable?

thank you if you read this far ;)

ASWC
03-14-2010, 06:32 AM
1. Are custom base classes the way to go on movie clip symbols and is this standard practice when building Flash projects?

Not at all. Base classes do have a purpose and this purpose is to allow duplication of functionality and behavior for a symbol. For this reason it makes sense to create and use a custom base class only if at least two symbols will use it. If only one symbol uses the custom base class then it would have been better to use a standard base class like MovieClip or Sprite.

2. Can I still eventually make the base classes abstract enough to be reusable?Absolutely, you could have a common set of DisplayObject for different symbol with same instance names and your base class can reference them and add default behavior for all these DisplayObjects. Of course a simple missing instance name or wrong type of object and the code breaks so it can become tricky to maintain.

I hope you are talking about the base class that you pass when exporting your symbol to actionscript and not the class you can set for your symbol. These are different things. In CS4 when you export for actionscript you have a text box called "class" and a text box called "base class", I'm referring to the second case.

Blitz3000
03-14-2010, 11:19 AM
ASWC: Thanks for your reply..

Ok so if I'm understanding correctly your answer on Q1.
If I were to build a menu I might create a MenuClass.as to add the menu background clip, button symbols, and handle all menu functionality. Then I would make a single ButtonClass.as and make it the Base Class for all the different button symbols and handle the duplicated functionality. sound ok??

I think I see what you mean in regards to Q2.
So then is it preferable to encapsulate a base class and keep the class that added it's abstract? for instance best practice is to try and make MenuClass.as abstract and try and make ButtonClass.as (being the Base Class) as encapsulated as possible?

In answer to your question: yes, i'm primarily referring to the base class you can set in the Linkage Properties dialog box. E.g. In the 'Base Class' input field I would put com.myclasses.utils.ButtonClass and in the 'Class' field I would put something like 'MenuMc'. again these aren't the real names it's just for the purpose of the questions above.

ASWC
03-14-2010, 01:16 PM
yes absolutely the purpose of the base class is to provide a common set of functionality for a number of object (typically more than one). It is much more like a class that all your object extend.

Ravi Bhadauria
02-20-2011, 11:17 AM
Nice post and answered well.

Can one try to expose something on Sprite and Extends MovieClip in actionscirpt 3.0, plz.



Thanks
admec multimedia