hrm actually heres a slightly revised version. Hope this helps


class ca.nectere.utils.ClassUtils{

   //create a movieClip and associate a class with it
   static public function CreateWithClass( classRef:Function,
target:MovieClip, name:String, depth:Number, params:Object ){
       if (depth == null) target.getNextHighestDepth();
       var mc:MovieClip=target.createEmptyMovieClip(name,depth);
       LinkWithClass(classRef, mc);
       if (params != null) for (var i in params) mc[i]=params[i];
       return mc;
   }

   //attach a movieClip from the library and associate a class with it
   static public function AttachWithClass( classRef:Function,
target:MovieClip, id:String, name:String, depth:Number, params:Object ){
       if (depth == null) target.getNextHighestDepth();
       var mc:MovieClip = target.attachMovie(id, name, depth, params);
       LinkWithClass(classRef, mc);
       return mc;
   }

   //link a class with an existing movieClip, use for _root / timeline
association
   static public function LinkWithClass( classRef:Function,
target:MovieClip ){
       target.__proto__ = classRef.prototype;
       classRef.apply(target);
       return target;
   }

}



On 9/20/06, Francis Turmel <[EMAIL PROTECTED]> wrote:

If this can be useful to anyone, I modified Danny's class to fit my needs
and used
it on several projects so far. Works like a charm.


class ca.nectere.utils.ClassUtils{

    //create a movieClip and associate a class with it
    static public function CreateWithClass( classRef:Function,
target:MovieClip, name:String, depth:Number, params:Object ){
        var mc:MovieClip=target.createEmptyMovieClip(name,depth);
        mc.__proto__ = classRef.prototype;
        if (params != null) for (var i in params) mc[i]=params[i];
        classRef.apply(mc);
        return mc;
    }

    //attach a movieClip from the library and associate a class with it
    static public function AttachWithClass( classRef:Function,
target:MovieClip, id:String, name:String, depth:Number, params:Object ){
        var mc:MovieClip = target.attachMovie(id, name, depth, params);
        mc.__proto__ = classRef.prototype;
        classRef.apply(mc);
        return mc;
    }

    //link a class with an existing movieClip, use for _root / timeline
association
    static public function LinkWithClass( classRef:Function,
target:MovieClip ){
        var mc:MovieClip = target;
        mc.__proto__ = classRef.prototype;
        classRef.apply(mc);
        return target;

    }

}




On 9/20/06, Adam Pasztory <[EMAIL PROTECTED]> wrote:
>
> I'm not a big fan of using Object.registerClass().  I find it creates a
> dependency between code and art assets that can be problematic.  If your
> MovieClip is changed, your won't be able to instantiate
> anymore.  Another
> problem with registerClass() is that it makes it difficult to change the
> source
> of the movie clip.  For example, if I decide I'd like to load an
> external
> SWF instead of attaching a clip from the library, my class won't work
> anymore.
>
> Like Jason, I use containment most of the time to encapsulate movie
> clips.
>
> On 9/20/06, slangeberg <[EMAIL PROTECTED]> wrote:
> >
> > Eka,
> >
> > Can you tell us what you're trying to accomplish with that
> DisplayFactory?
> >
> > Usage example?
> >
> > Scott
> >
> > On 9/20/06, eka <[EMAIL PROTECTED] > wrote:
> > >
> > > Hello :)
> > >
> > > with Vegas : http://osflash.org/vegas
> > >
> > > you can use the class DisplayFactory :
> > >
> > >
> >
> 
http://svn1.cvsdude.com/osflash/vegas/AS2/trunk/src/vegas/util/factory/DisplayFactory.as
> > >
> > > Install the AS2 src of vegas in your classpaths and test the example
> :
> > >
> > >
> > http://svn1.cvsdude.com/osflash/vegas/AS2/trunk/bin/test/vegas/util/factory/
>
> > >
> > > You can try my example too in Lunas, the Components library
> extension of
> > > vegas :
> > >
> > >
> >
> 
http://svn1.cvsdude.com/osflash/vegas/AS2/trunk/bin/test/lunas/display/components/button/
> > >
> > > EKA+ :)
> > >
> > > 2006/9/20, Alain Rousseau <[EMAIL PROTECTED] >:
> > > >
> > > > There is an interesting article on the subject in the Flashcoder's
> > Wiki
> > > > at osflash.org :
> > > >
> > > >
> > >
> > 
http://www.osflash.org/flashcoders/as2#creating_a_class_instance_based_on_movieclip_without_a_symbol_in_the_library
>
> > > >
> > > > With this approach you can create a class that extends MovieClip
> and
> > > > then create an instance of that class without a symbol in the
> library.
> > I
> > > > found it very useful and really neat ! works like a charm !
> > > >
> > > >
> > > > Alain
> > > >
> > > > Geoff Stearns wrote:
> > > >
> > > > > it does work in flash 8.
> > > > >
> > > > > as for clips on the stage, it does work, you just have to give
> the
> > > > > clip a linkage ID in the library first, and use that linkage to
> > > > > register the class to it.
> > > > >
> > > > >
> > > > > On Sep 19, 2006, at 5:31 PM, slangeberg wrote:
> > > > >
> > > > >> Does Object.registerClass() work in Flash 8 (i haven't been
> able to
> > > > >> get it
> > > > >> to work)?  Also, does that allow you to register more than one
> clip
> > > > >> with a
> > > > >> class?
> > > > >>
> > > > >> The documentation seems to point to using the Linkage setting
> for
> > > AS2:
> > > > >>
> > > > >> *> Availability: *ActionScript 1.0; Flash Player 6 - If you are
> > using
> > > > >> ActionScript 2.0 classes, you can use the ActionScript 2.0Class
> > > > >> field in
> > > > >> the Linkage Properties or Symbol Properties dialog box to
> associate
> > > an
> > > > >> object with a class instead of using this method.
> > > > >>
> > > > >>
> > > > >> Also, I don't think it works for clips that you've dragged to
> the
> > > > >> stage:
> > > > >>
> > > > >>> When an instance of the specified movie clip symbol is created
> by
> > > > >>> using
> > > > >>
> > > > >> MovieClip.attachMovie() or MovieClip.duplicateMovieClip(), it
> is
> > > > >> registered
> > > > >> to the class specified by theClass
> > > > >>
> > > > >> Scott
> > > > >>
> > > > >>
> > > > >> On 9/19/06, Geoff Stearns <[EMAIL PROTECTED] > wrote:
> > > > >>
> > > > >>>
> > > > >>> that article was only meant for assigning a class to your
> _root
> > > > >>> timeline... I don't think he intended it to be used for other
> > > > >>> movieclips in the library or on stage.
> > > > >>>
> > > > >>> for that you could just use the linkage in the library or use
> > > > >>> Object.registerClass()
> > > > >>>
> > > > >>>
> > > > >>>
> > > > >>>
> > > > >>>
> > > > >>> On Sep 19, 2006, at 4:29 PM, slangeberg wrote:
> > > > >>>
> > > > >>> > I was looking at Danny's article regarding a Flash
> > Document  Class
> > > > >>> at:
> > > > >>> >
> > > > >>> >
> > > http://www.dannypatterson.com/Resources/Blog/EntryDetail.cfm?id=106
> > > > >>> >
> > > > >>> > And i started to wonder if people are using this to
> associate
> > > their
> > > > >>> > clips on
> > > > >>> > stage with a class?
> > > > >>> >
> > > > >>> > Are people doing this kind of thing (or otherwise) instead
> of
> > > > >>> > setting the AS
> > > > >>> > 2.0 class property in the 'linkage' dialog of their
> > movieclips  in
> > > > >>> the
> > > > >>> > library?
> > > > >>> >
> > > > >>> > I just hate how it's not obvious (by linkage) which class is
> > being
> > > > >>> > used in
> > > > >>> > Flash 8.0. Only gets me more excited for some Flash 9.0projects
> > > to
> > > > >>> > come
> > > > >>> > through!
> > > > >>> >
> > > > >>> > : : ) Scott
> > > > >>> > _______________________________________________
> > > > >>> > 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
> > > > >>>
> > > > >>> _______________________________________________
> > > > >>> 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
> > > > >>>
> > > > >>
> > > > >>
> > > > >>
> > > > >> --
> > > > >>
> > > > >> : : ) Scott
> > > > >> _______________________________________________
> > > > >> 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
> > > > >
> > > > >
> > > > > _______________________________________________
> > > > > 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
> > > > >
> > > > >
> > > > >
> > > > _______________________________________________
> > > > 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
> > > >
> > > _______________________________________________
> > > 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
> > >
> >
> >
> >
> > --
> >
> > : : ) Scott
> > _______________________________________________
> > 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
> >
> _______________________________________________
> 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
>




--
Francis Turmel
Personal: [EMAIL PROTECTED]
Business: [EMAIL PROTECTED]
_______________________________________________
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