Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Remove a child; replace it with another child, with SAME NAME??

Contributor ,
Jul 09, 2013 Jul 09, 2013

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

TOPICS
ActionScript
387
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 10, 2013 Jul 10, 2013
LATEST

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();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines