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

addChildAt for top layer confusion

Contributor ,
Jan 29, 2016 Jan 29, 2016
//Level 2

if (score==10 && score<30 ){

var myMovieClipbg:winbg = new winbg();

myMovieClipbg.x = 0;

myMovieClipbg.y = 5;

addChildAt(myMovieClipbg,1);

}

//level 3

else if (score>30 && score<60){

var lastmc:tired = new tired();

lastmc.x = 0;

lastmc.y = 0;

addChildAt(lastmc, 1);

}

"lastmc" should be top layer background when score is greater than 30 . but its not working . moreover if i use addChild(lastmc) . it becomes top of all layer . so My hero and enemies everything go down. i can not play . but  need lastmc just top of myMovieClipbg background layer .

i assume the confusion coming from addChildAt


note addChildAt(myMovieClipbg,1); is working fine for second level. it brings the background top of first background .

but addChildAt(lastmc, 1); is failing to bring the background of of second background

TOPICS
ActionScript
633
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

correct answers 1 Correct answer

Community Expert , Jan 29, 2016 Jan 29, 2016

try:

tanvira5454192 wrote:

//Level 2

if (score==10 && score<30 ){

var myMovieClipbg:winbg = new winbg();

myMovieClipbg.x = 0;

myMovieClipbg.y = 5;

addChildAt(myMovieClipbg,1);

}

//level 3

else if (score>30 && score<60){

var lastmc:tired = new tired();

lastmc.x = 0;

lastmc.y = 0;

myMovieClipbg.addChild(lastmc);

}

Translate
Community Expert ,
Jan 29, 2016 Jan 29, 2016

try:

tanvira5454192 wrote:

//Level 2

if (score==10 && score<30 ){

var myMovieClipbg:winbg = new winbg();

myMovieClipbg.x = 0;

myMovieClipbg.y = 5;

addChildAt(myMovieClipbg,1);

}

//level 3

else if (score>30 && score<60){

var lastmc:tired = new tired();

lastmc.x = 0;

lastmc.y = 0;

myMovieClipbg.addChild(lastmc);

}

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
Contributor ,
Jan 29, 2016 Jan 29, 2016

kglad sir ,

it still does not working

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
Community Expert ,
Jan 29, 2016 Jan 29, 2016

what do you see that makes you think it's not working?

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
Contributor ,
Jan 29, 2016 Jan 29, 2016

TypeError: Error #1009: Cannot access a property or method of a null object reference.

  at csdone_fla::MainTimeline/FRAME()

yes. this error does not come if i write addChild(lastmc);

but it comes if i write your code myMovieClipbg.addChild(lastmc);

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
Community Expert ,
Jan 29, 2016 Jan 29, 2016

then either myMovieClipbg doesn't exist, or you made it local to a function or some other timeline.

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
Contributor ,
Jan 30, 2016 Jan 30, 2016

yes. now its working . its my bad. i fixed the bug . and now myMovieClipbg.addChild(lastmc); working fine

thanks sir for helping

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
Community Expert ,
Jan 30, 2016 Jan 30, 2016
LATEST

you're welcome.

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