Copy link to clipboard
Copied
Hi there!
I have an app, that somewhere in the top of code (as3) I have added a movie clip:
...
var appTXT:textMV00 = new textMV00();
addChild(appTXT);
...
then in another function, I need to remove that child, and replace it with another child BUT with the same name!!
(Because the app dynamically set the position, swip etc. based on the name "appTXT", so I need to have the same name)
When I remove it and add another child with same name like this:
removeChild(appTXT);
var appTXT:Ch1 = new Ch1();
addChildAt(appTXT,1);
I receive this error:
TypeError: Error #2007: Parameter child must be non-null.
at flash.display::DisplayObjectContainer/removeChild()
at Quran23_fla::MainTimeline/appStart()[Quran23_fla.MainTimeline::frame1:135]
at Quran23_fla::MainTimeline/APPLoop()[Quran23_fla.MainTimeline::frame1:49]
However, if I replace the code with this:
...
removeChild(appTXT);
var anyOtherVariableName:Ch1 = new Ch1();
addChildAt(anyOtherVariableName,1);
...
Then it works fine with no Errors! But does not solve my problem.
So would anyone help me please find out how should I remove a child, and replace it with another child, with the "SAME NAME"??
Yours, Ali
Copy link to clipboard
Copied
Do not declare the same variable twice. Declare it once with a wildcard designation and then use it to create new instances....
var appTXT:*;
...
appTXT = new textMV00();
...
appTXT = new Ch1();
Find more inspiration, events, and resources on the new Adobe Community
Explore Now