Trying to clear many instances from stage at once
I am making a flashcard game with five subjects. It has buttons for moving forward and back,and buttons for switching to another subject. The card instances for each subject are stored offstage, in separate frames (five in all), and their names are stored in arrays (five in all). Each time a button is pressed, the appropriate card tweens onto the stage.
When a user goes back to the menu frame, any instances brought to stage up until that point were still visible (not sure why, since the menu's on it's own frame), so I wrote a function to clear everything offstage whenever the menu button is clicked.
My problem is weird: if you are in the math subject, switching to geography returns this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at flashcardapp1_fla::MainTimeline/frame3()
at flash.display::MovieClip/gotoAndStop()
at flashcardapp1_fla::MainTimeline/subjectselected()
at flashcardapp1_fla::MainTimeline/selectgeo()
After that, you can still move from card to card, but clicking to go back to the menu freezes everything.
Is there some easier way to clear instances from the stage that I am missing?
I think my error must be in this code here, but I'm at a loss to find it. Please help! Still very new to Flash.
function gotomenu (e:MouseEvent):void {instancehide(); gotomenubeenclicked = true; gotoAndStop(1);}
function selectgeo(e:MouseEvent):void {subj = "geo"; relevantframe = 3; subjectselected(); geobeenclicked = true; }
function subjectselected():void {instancehide(); currentcard = subj + limitfaces + currentcard.substr(7,8); if (currentFrame > 1) {gotoAndStop(relevantframe); childindex(); slidefromrightfunc();}}
var grmbeenclicked:Boolean var latbeenclicked:Boolean var matbeenclicked:Boolean var geobeenclicked:Boolean var hisbeenclicked:Boolean function instancehide():void {if (matbeenclicked == true) {for (var imatfrnt:uint = 0; imatfrnt<allmat.length; imatfrnt++) {var matelement:MovieClip = allmat[imatfrnt] as MovieClip; matelement.x = hiddenx; matelement.alpha = 0;} } if (geobeenclicked == true) {for (var igeofrnt:uint = 0; igeofrnt<allgeo.length; igeofrnt++) {var geoelement:MovieClip = allgeo[igeofrnt] as MovieClip; geoelement.x = hiddenx; geoelement.alpha = 0;} for (var igeomaps:uint = 0; igeomaps<allmaps.length; igeomaps++) {var mapelement:MovieClip = allmaps[igeomaps] as MovieClip; mapelement.x = hiddenx; mapelement.alpha = 0;} } grmbeenclicked = false; latbeenclicked = false; matbeenclicked = false; geobeenclicked = false; hisbeenclicked = false; }
