Skip navigation
Currently Being Moderated

one class multiple movieclips

Apr 24, 2012 1:58 AM

Hi,

 

again I ran into the dilemma of having one class on one Movieclip an then  want to use the same class on another clip. Setting it on the other library clip doesn't work. I tried to use a new class that extends my class but extending a movieclip extended class seems to lead to errors in flash.

 

Is there a clean way w/o reprogramming my class to do this? Or would I copy my class multiple times with another name?

 

TIA

 
Replies
  • Currently Being Moderated
    Apr 24, 2012 4:18 AM   in reply to FlashGodThe2nd

    If they are different symbols in the library I would have different class names for them.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 24, 2012 5:15 AM   in reply to FlashGodThe2nd

    You could have each symbol import the class if it will remain the same for all of them.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 24, 2012 6:44 AM   in reply to FlashGodThe2nd

    You could not link the class to the clip using the clip properties and instead define a clip variable in your class, and just use the clip's linkage name to instantiate different clips. Example you might have a dialog class and want to use different dialogs... you might do something like:

     

    private var clip:MovieClip;

    public function Dialog(which:int):void

    {

         if(which == 1){

              clip = new simpleDialog(); //library clip

         }else{

              clip = new yesNoDialog(); //lib clip

         }

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 24, 2012 8:16 AM   in reply to FlashGodThe2nd

    What kind of problems are you having extending and extended MovieClip? That shouldn't cause problems.

     

    And like dmennenoh says if the two appearances are really "the same class" but only differ in their appearance, then you can think of that as some kind of "skin class" or such and have all the basic functionality and then choose the correct skin in the constructor or with some kind of method.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 24, 2012 12:55 PM   in reply to FlashGodThe2nd

    I guess I'm not understanding what you are (trying to) do.

     

    I made a class:

     

    package {

     

              import flash.display.MovieClip;

     

              public class ContentFader extends MovieClip{

     

                        public function ContentFader(){

                                  trace("I am a contentFader instance.");

                        }

     

              }

     

    }

     

    I then made two different symbols in my library Content1 and Content2, both of which extend ContentFader. I don't get any errors and both of them call the constructor of the super class.

     

    So what am I missing?

     

    PS: Good habit to get into -- making class names capital.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 24, 2012 1:26 PM   in reply to Rothrock

    >>I then made two different symbols in my library Content1 and Content2, both of which extend ContentFader. I don't get any errors and both of them call the constructor of the super class.

     

    Can you maybe explain how you did that? You can't use the same class linkage, so I'm wondering what exactly you did.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 24, 2012 3:40 PM   in reply to dmeN

    The Class for Content1 was Content1 and its Base class was ContentFader. Likewise Content2 is Class: Content2 and Base class ContentFader.

     

    Then just to mix it up a little. I created a Content1.as file, but none for Content2. Everything works as I would expect.

     

    I'm guessing it is that all y'all were thinking that base class meant something other that what I think it means? If that was the case it would need to say DisplayObject or in all reality Object.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 25, 2012 7:07 AM   in reply to FlashGodThe2nd

    Glad that helped. You should probably figure out what it is complaining about. At work I have a lot of Flash developers. For some reason there are a group of them who never read those warning/error messages. And then at some point they are always amazed when it all breaks.

     

    At least you are reading the messages! But do something about them sooner rather than later.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points