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

_root.MC.Mc2 is working but put the 3rd mc, it isn't. WHY?

New Here ,
Feb 25, 2014 Feb 25, 2014

I can't figure how to reach to the MC which is inside other 2 MCs.

like :>> BG>Phone>base7.

I want to get to base 7 and use it on hittestobject. But it doesn't work as I use just _root.BG.Phone

This is my code.

// just so you know I have put _root = MovieClip(root); on function before this, so I can use _root.

private function checkKeys2(e:KeyboardEvent):void{

                              //checking if a certain key is down and it's touching the receptor

                              if(e.keyCode == arrowCodePhone && this.hitTestObject(_root.BG.Phone.base7)){

                                        //checking if the correct key is down

                                        //if the user hits it about perfectly

                                        //the receptors y coordinate is about 10 px away from the

                                        //symbol's y coordinate.

                                        if(this.y <= _root.BG.Phone.y -1 && this.y >= _root.BG.Phone.y-50){

                                                  _root.score -= 10;

                                                  _root.scoreString = 'Too SLOW';

                                                  _root.changeHealth(-8);

                                        }

                                        else if(this.y <= _root.BG.Phone.y +60 && this.y >= _root.BG.Phone.y+0){

                                                  _root.score += 10;

                                                  _root.scoreString = 'Perfect:D';

                                                  _root.changeHealth(10);

                                        } else if (this.y <= _root.BG.Phone.y +120 && this.y >= _root.BG.Phone.y +61){

                                                  _root.score += 8;

                                                  _root.scoreString = 'Awesome';

                                                  _root.changeHealth(7);

                                        } else if (this.y <= _root.BG.Phone.y +110 && this.y >= _root.BG.Phone.y +91){

                                                  _root.score += 6;

                                                  _root.scoreString = 'Nice :)';

                                                  _root.changeHealth(5);

                                        }

                                         else {

                                                  _root.score += 4;

                                                  _root.scoreString = 'Too quick!!';

                                                  _root.changeHealth(2);

                                        }

                                        _root.combo ++;

                                        destroyThisPhone();//remove it from stage

                              }

                    }

When it gets into this function, it just gose through the 'else' instead of checking if. I always got "Too quick". But after I take the base 7 out after the Phone, it actully works again.

I want to know WHY? I can't use this to the 3rd degree MCs or it is fine but may be something else's wrong.

TOPICS
ActionScript
393
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 ,
Feb 25, 2014 Feb 25, 2014

this:

this.y <= _root.BG.Phone.y -1 && this.y >= _root.BG.Phone.y-50

will never be true.

maybe you want:

this.y >= _root.BG.Phone.y -1 && this.y <= _root.BG.Phone.y-50
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
New Here ,
Feb 25, 2014 Feb 25, 2014

​​No, It is working . I want the space between -50 to -1 so y<-1 and y>-50.
It works when there is no base 7
My question is
How to reach to base 7 if I can't write it like : _root.BG.Phone.base7

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 ,
Feb 25, 2014 Feb 25, 2014

oops, your right.

use the trace function to see what you're doing:

// just so you know I have put _root = MovieClip(root); on function before this, so I can use _root.
 
private function checkKeys2(e:KeyboardEvent):void{
                              //checking if a certain key is down and it's touching the receptor
                              if(e.keyCode == arrowCodePhone && this.hitTestObject(_root.BG.Phone.base7)){ 
                                        //checking if the correct key is down
                                        //if the user hits it about perfectly
                                        //the receptors y coordinate is about 10 px away from the
                                        //symbol's y coordinate.
trace(this.y,_root.BG.Phone.y);

                                         if(this.y <= _root.BG.Phone.y -1 && this.y >= _root.BG.Phone.y-50){                                                   _root.score -= 10;                                                   _root.scoreString = 'Too SLOW';                                                   _root.changeHealth(-8);                                         }                                         else if(this.y <= _root.BG.Phone.y +60 && this.y >= _root.BG.Phone.y+0){                                                   _root.score += 10;                                                   _root.scoreString = 'Perfect:D';                                                   _root.changeHealth(10);                                         } else if (this.y <= _root.BG.Phone.y +120 && this.y >= _root.BG.Phone.y +61){                                                   _root.score += 8;                                                   _root.scoreString = 'Awesome';                                                   _root.changeHealth(7);                                         } else if (this.y <= _root.BG.Phone.y +110 && this.y >= _root.BG.Phone.y +91){                                                   _root.score += 6;                                                   _root.scoreString = 'Nice :)';                                                   _root.changeHealth(5);                                         }                                          else {                                                   _root.score += 4;                                                   _root.scoreString = 'Too quick!!';                                                   _root.changeHealth(2);                                         }                                         _root.combo ++;                                         destroyThisPhone();//remove it from stage                               }                     }

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
New Here ,
Feb 25, 2014 Feb 25, 2014

hmm... I did. That's why I know the function itself works. But it didn't come in the 'if' to use hitTestObject. :[ Or it came in but just can't find base7.

So you think that _root.BG.Phone.base7 is already correct, right?

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 ,
Feb 25, 2014 Feb 25, 2014
LATEST

did that trace ever show values that would trigger the if-branch?

if you think so and you think it did not trigger the if-branch copy and paste the trace output when using the following and the appropriate triggering values:

trace(this.y,_root.BG.Phone.y);

                                         if(this.y <= _root.BG.Phone.y -1 && this.y >= _root.BG.Phone.y-50){

trace("triggered"):

                                                  _root.score -= 10;
                                                  _root.scoreString = 'Too SLOW';
                                                  _root.changeHealth(-8);
                                        }

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