This is more a question about writing the code than a particular problem (although it is a particular problem). Note, I'm self taught so there is much I do not know in case this is a realtively simple issue:
I have a movie clip for which I've created a class. On my main timeline, I've instatiated (addChild) it within a function using a variable within that function, e.g.,:
function myfunction():void {
var newInstance:MovieClip = new myCreatedClassForTheMovieClip();
addChild(newInstance);
....
}
Within my movie clip, I reference a variable on the main timeline: movieClipVar = MovieClip(root).mainTimeLineVariable;
I get error Error #1009: Cannot access a property or method of a null object reference.
When I make the variable declaration for the new instance of the movie clip outside of the function but at the global level, I don't get that error BUT, when I try to removeChild(newInstance) I get compiler error 1120 : access of undefined property newInstance (which does make sense since it isn't instantiated yet).
So, I'm not sure how the two objects are working together (the instantiated movie clip and main timeline) and why the movie clip can't see the varaible on the timeline even with MovieClip(root) to point it there.
Thanks for any help or guidance on this.
Cheers,
Mike
edit: When I declare the newInstance
globally, I instantiate it the same way in the function, just omitting the var statement and using the addChild(newInstance)
.
Here's the function that removes the movie clip:
function postResponseCleanUp(): void {
switch (lessonStep) {
case 1 :
break;
case 2 :
break;
case 3 :
break;
case 4 :
//removeChild(screenPrint); <<previous way
removeChild(getChildByName("screenPrintName")); // cludgy way
removeChild(getChildByName("idaWkSheetName"));
if (userRole == 1) { // witness
faderOverlay.visible = false;
instructionsCallout.callout_ta.htmlText ="<font size ='6'>The <font color='#0000FF'>Reconciler</font> continues processing the notes, repeating this process <i>for each deonmination</i>.<br><br>Click <b>Next</b> to see the next steps in the process.</font>";
} else {
instructionsCallout.callout_ta.htmlText ="<font size ='6'>You continue processing the notes, repeating this process <i>for each deonmination</i>.<br><br>Click <b>Next</b> to see the next steps in the process.</font>";
}
removeChild(pointerNew);
idaWkSheet.removeEventListener(MouseEvent.ROLL_OVER,boardOver);
//screenPrint.removeEventListener(MouseEvent.ROLL_OVER,boardOver);
Mouse.show();
break;
case 5 :
break;
}
}
mainTimeLineVariable
var – BadFeelingAboutThis