PDA

View Full Version : creating a new instance fails when base class is assigned to an external class file


aldmck
07-22-2009, 03:23 AM
I'm trying to create a new instance of a MovieClip when the original one has been used. Would sound easy enough. Just use: var instanceName:ClassName = new ClassName();

the class name/mc in the library im trying to duplicate is MCg1

so

var instanceName:MCg1 = new MCg1(); right?

However, the particular object in the library i'm trying to duplicate has a base class that is an external class file (just to control it's drag drop functionality)... i.e baseclass is not set to the standard flash.display.MovieClip, or whatever the case maybe. So i end out with a: TypeError: Error #1009: Cannot access a property or method of a null object reference.


any ideas with whats going wrong?

lordofduct
07-22-2009, 03:26 AM
does the base class extend Sprite or MovieClip???

If there is more then one frame in the actual graphics of it then it need to be MovieClip, if it doesn't you can use Sprite if you want to keep object complexity down.

aldmck
07-22-2009, 04:06 AM
The DragDrop class extends MovieClip. When i originally used it, it was for multiframe objects. This time I could change it to sprite, but just haven't seen the need until maybe now?????

lordofduct
07-22-2009, 04:07 AM
nah, MovieClip extends Sprite, so you can keep it MovieClip. I just don't use MovieClip unless I think I need the functionality of MovieClip for something (all MovieClip adds to Sprite is the timeline functionality).

aldmck
07-22-2009, 06:11 AM
so couldnt hazard a guess as to why it's giving me an error message. It's weird, I changed the base class from DragDrop to the MovieClip class and it worked fine (but couldn't drag them anymore). Even though the class extends the MovieClip class its as if it's not registering that there is actually any type of object there (even though it's sitting there in the library with the MCg1 class name!).

After the object is duplicated, is there anyway i could apply the dragdrop class to each new instance using actionscript?

lordofduct
07-22-2009, 07:16 AM
when the error fires does it direct you to any line of code or anything? Usually somehting like doublic clicking the error brings you to the location at which it occurred.

aldmck
07-22-2009, 08:43 AM
it spits the error out in the output window rather than compiler errors. It says the error is in the function where this is: var instanceName:MCg1 = new MCg1();

As i said before if i change the base class to something more standard, then the duplication works fine. So the problem is definitely in that im trying to duplicate an instance whose MovieClip is attached to an external base class, rather than a standard flash one.