A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Game not tracking hit and miss

  1. #1
    Junior Member
    Join Date
    Oct 2008
    Posts
    6

    Game not tracking hit and miss

    I have built a whack a mole style game that works (with some help from this forum).
    I now want to place that game inside another flash site. I've tried adding it as an extern swf (on click - load movie) and as a movieclip inside the new flash site. The game works in both methods (it runs a bit slow and jerky - but thats another problem) but the game does not count the times you hit the mole and the times you miss.

    My guess is that the coding isn't specific enough and there is confussion in regestering the hits because of the various levels of the flash site (after all - it works as a stand alone game.)

    This is the code for changing the mouse graphic and the actions:

    stop();
    Mouse.hide();
    mallet.stop();
    mallet._x = _xmouse;
    mallet._y = _ymouse;
    function checkHits(mc) {
    point = {x:mc._x, y:mc._y}
    mc._parent.localToGlobal(point);
    if (_root.hole.pancake.hitTest(point.x, point.y)) {
    trace("hit");
    }
    }
    mallet.onMouseDown = function() {
    this.gotoAndStop(2);
    checkHits(this.head);
    this.onMouseUp = function() {
    this.gotoAndStop(1);
    };
    };
    mallet.onMouseMove = function() {
    mallet._x = _xmouse;
    mallet._y = _ymouse;
    };

    This is the code for the objects that you hit:

    if (smacked) {
    _root.hits++;
    } else {
    _root.misses++;
    }

    This is the code when game time has ended:

    if ( _root.hits> _root.misses ) {
    _root.gotoAndPlay("win");

    } else {
    _root.gotoAndPlay("lose");
    }


    I've tried replacing the use of '_root' with 'this' which didn't make a difference. I've tried putting the Mouse action script in the main flash level instead of the game movie clip - but that didn't work.
    Thanks for any help.

  2. #2
    Senior Member
    Join Date
    Feb 2004
    Posts
    312
    you are using _root. that means that your _root. might be referencing to the _root of the the flash site you are trying to embed yours.

    http://livedocs.adobe.com/flash/mx20...=00001522.html

  3. #3
    Junior Member
    Join Date
    Oct 2008
    Posts
    6
    i had that thought and tried replacing all instances of '_root' with 'this' thinking that 'this' would mean the game movieclip. but that didn't work.

    Could the solution be to use the _root tag but add the game movieclip name to make the trail specific (_root.whackgame.)?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center