Hey all,

Thanks for all the insights!


Sounds like you are trying to extend an instance of a MovieClip...

Yes, this mistake did creep into my thinking a bit-- thanks for getting me back on track!

I'm trying to create code such that a graphic designer can hand me a movieClip and I can slap a class on it to define behavior integral to the movieClip ("extends MovieClip"). An instance of the movieClip would then instantiate the class, with the possibility of passing arguments to the constructor. I'd also like to use multiple inheritence, but I think I can work around that by using sub-classes:

        private var type1handler;
        private var type2handler;
        
        function blah( type1:String, type2:String ) {
                switch(type1) {
                        case a:  type1handler = new <class1_a>
                        case b:  type1handler = new <class1_b>
                }
                switch(type2) {
                        case a:  type2handler = new <class2_a>
                        case b:  type2handler = new <class2_b>
                }
        }



From: "Andrei Thomaz" <[EMAIL PROTECTED]>

class MyMenu extends MovieClip
{
  var m_btnButton1:MovieClip; // or a derived-MovieClip class;
                                            // I created a class for
buttons, for example

  function init()
  {
    m_btnButton1.onRelease = function ()
    {
      // handle release here
    }
  }
}

Hmm... interesting thought... invert the thinking somewhat:

class superblah {
        public var blah:MovieClip;
        
        function superblah() {
                blah = create and attach designer movieClip;
                blah.onRelease = function...
        }
}


From: Rákos Attila <[EMAIL PROTECTED]>

Do you mean that setting the associated AS 2.0 class in the
MovieClip's linkage settings is not an option and you want to alter
the class of an existing MovieClip instance at run-time? It's possible
by utilizing the __proto__ property and reorganizing the prototype
chain.

But your code seems to be not optimal:
1. unnecessary and superfluous to create a wrapper function for each
   instance's onRelease handler (it creates as many Function instances
   as many blah instance is created)

Agreed it's unnecessary and superfluous, and looking for a better way...

Truthfully, I've never used the AS 2.0 class in the linkage box-- this may be what I was looking for! Can this be set up so that instances can then pass parameters to the class's constructor?

mucking with the __proto__ may work as well...

(And your example, of course, is more like what I'd meant:)

2. the same with setting the handler function in the constructor,
   since it can be a simple class member

class blah extends MovieClip {

  private function onRelease(): Void {
    // handle release here
  }

}


Thanks again,
--Dave


_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to