Copy link to clipboard
Copied
I am attempting to have the code check to see if a movieclip is present and if it is then remove it when the user exits (or comes back) the application from the device (through a phone call, menu press etc).
In my app when the user exits the application they are given the option of resuming from the same point or going to the first screen.
If a movie clip is on screen then and the user resumes then there is not a problem.
If a movie clip is on screen and the user clicks restart this is where the probelm occurs and I get an error (or nothing happens, depending on the different coding options i've tried).
My intent here is to have the system check for the movie clip and remove them when the app is reactivated via the restartF function. Refer to the code section below.
TypeError: Error #2007: Parameter child must be non-null.
at flash.display::DisplayObjectContainer/addChild()
For example:
Frame 1 (This would represent the statements in blue)
var mywordGrumpy:vocabulary_Grumpy = new vocabulary_Grumpy();
var mywordIncline:vocabulary_incline = new vocabulary_incline();
I have narrowed the problem to the restartF function in the code below:
Code Section:
//Adds pop-up screen and asks would they like to resume or restart.
function onComeBack(event:Event):void
{
NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;
if (! modalW)
{
modalW = new ModalW();
addChild(modalW);
modalW.x = -97;
modalW.y = -8;
modalW.resumego.addEventListener(MouseEvent.CLICK,resumeF);
modalW.restartgo.addEventListener(MouseEvent.CLICK,restartF);
}
else
{
addChild(modalW);
}
}
//Triggered by resume touch and takes the user back to where they left.
function resumeF(e:MouseEvent):void
{
removeChild(e.currentTarget.parent);
gotoAndStop(so.data.currentFrame,so.data.currentSceneName);
}
//Triggered by restart and takes the user to the main screen. If statements removes the movieclips if present.
function restartF(e:MouseEvent):void
{
if (addChild(myPlayCredits))
{
removeChild(myPlayCredits);
}
if (addChild(myPlayAbout))
{
removeChild(myPlayAbout);
}
if (addChild(myPlayAuthor))
{
removeChild(myPlayAuthor);
}
if (addChild(mywordGrumpy))
{
removeChild(mywordGrumpy);
}
if (addChild(mywordIncline))
{
removeChild(mywordIncline);
}
if (addChild(mywordOodles))
{
removeChild(mywordOodles);
}
removeChild(e.currentTarget.parent);
gotoAndStop("1","MainScene");
}
What am I doing wrong?
I found the answer:
The variable declarations were not on the same frame as the if/then statements. I solved the problem by adding (for each variable):
var mywordGrumpy:vocabulary_Grumpy = new vocabulary_Grumpy();
var mywordIncline:vocabulary_incline = new vocabulary_incline();
var mywordOodles:vocabulary_oodles = new vocabulary_oodles();
This solved the problem! At the time the variables were being called they had not been declared, thus they had no value, thus the error message.
Copy link to clipboard
Copied
Anybody out there?
Copy link to clipboard
Copied
I found the answer:
The variable declarations were not on the same frame as the if/then statements. I solved the problem by adding (for each variable):
var mywordGrumpy:vocabulary_Grumpy = new vocabulary_Grumpy();
var mywordIncline:vocabulary_incline = new vocabulary_incline();
var mywordOodles:vocabulary_oodles = new vocabulary_oodles();
This solved the problem! At the time the variables were being called they had not been declared, thus they had no value, thus the error message.