Fwd: [Flashcoders] sharing a class with several movieclips, in AS3

0 views
Skip to first unread message

Andrei Thomaz

unread,
Mar 14, 2007, 12:47:08 AM3/14/07
to gug...@googlegroups.com
hello list,

i would like to ask you what do you think is the best way to implement the Button class in AS3. I created a simple class, based in the ideas explained in "Anatomy of a Button in Gugga Framework", but now I am thinking about which is the best way to solve the problem that I cann't share the same class with several movieclips in AS3.

Below, I am sending the question I sent to flashcoders, and some of the answers.


thank you,
andrei

-------------------------------------------------------------------------------------------------------------------------------------
ORIGINAL QUESTION
-------------------------------------------------------------------------------------------------------------------------------------

With AS2, I could associate the same class with several movieclips. This was useful, for example, to create buttons for a menu, when all the buttons were associated with the same class (some kind of button, that implemented the 'selected' state, rollout and rollover animations, and so on).

Now, I am trying to migrate the code to AS3, and I am having problems to share the same class with more than one movieclip. When I try to do this, I get this error: "You must specify a unique classname to export this symbol".

Can I make this, in some way? The only thing i can think is not very elegant; it would be to create empty classes for each button, like that:

class MyButton extends MovieClip
{
    // code here
}

class MyButton01 extends MyButton
{
    // nothing
}

class MyButton02 extends MyButton
{
    // nothing
}


-------------------------------------------------------------------------------------------------------------------------------------
SOME ANSWERS
-------------------------------------------------------------------------------------------------------------------------------------

---------- Forwarded message ----------
From: Andrei Thomaz <andrei...@gmail.com >
Date: Mar 12, 2007 11:23 AM
Subject: Re: [Flashcoders] sharing a class with several movieclips, in AS3
To: flash...@chattyfig.figleaf.com

hello Charles,

In respect to AS 3, I agree with you: create specialized classes is against OOP, and the idea of having different movieclips being loaded for each button is good.

The good thing of the old solution (the same used by gugga ff) is that having all the animations of a button in a single timeline seems a bit easier to visualize (for a designer) than to split the animations along three of more movieclips. And all that I needed was a single class for all the buttons.

thank you,
andrei




On 3/12/07, Charles Parcell <pokemo...@gmail.com> wrote:
Sounds like you are negating the whole purpose of classes.

How about a little reengineering of the buttons.

Build your single class and have multiple instances of the button on screen.
Part of the class would be to load in the proper animation MC for display.
Thus you have the single class that is applied to all buttons and each
button has an independent animation associated with it.

Or if you wanted, you could do as you listed in your first e-mail and extend
a single base class and make specialized classes for each button. But again,
that is sort of defeating the purpose of classes and OOP.

Charles P.


On 3/12/07, Andrei Thomaz < andrei...@gmail.com> wrote:
>
> hello Janis,
>
> the problem is that I don't want several instances of same symbol in the
> stage. Imagine a menu for the sections of a site: you have a button, with
> some animations, for each section. So, I cann't use several instances of a
> same symbol. What I want, and what it was done with AS 2, was to have a
> symbol for each button, and associate the symbols with the same class,
> what,
> I am afraid, it is not possible in AS 3.
>
> What I am doing is similar with the buttons in Gugga framework (you can
> read
> about the buttons in GuggaFF here, http://www.gugga.com/flashblog/ )
>
>
> []'s
> andrei
>

Reply all
Reply to author
Forward
0 new messages