multiple hittests in action script with "for"

  • rejoin
  • Born
  • Born
  • rejoin
  • Posts: 1

Post 3+ Months Ago

this is supposet to make multiple hittests for the movieclips block2, block3, block4... it doesnt seem to work. i just don't know what im doing wrong, if i just type in the number of the block manually instead of useing the "init" variable it works fine.

Code: [ Select ]
onClipEvent (enterFrame) {
    for (init=1; init<=10; init++) {
        if (_root.stage["block"+init].hitTest(_x+30, _y+48)) {
            gravity = 0;
            jump = false;
            jumpcount = 0;
        }
        if (!(_root.stage["block"+init].hitTest(_x+30, _y+48)) and jump == false) {
            gravity = gravityval;
            moy = 0;
            jumpcount = 0;
        }
    }...
  1. onClipEvent (enterFrame) {
  2.     for (init=1; init<=10; init++) {
  3.         if (_root.stage["block"+init].hitTest(_x+30, _y+48)) {
  4.             gravity = 0;
  5.             jump = false;
  6.             jumpcount = 0;
  7.         }
  8.         if (!(_root.stage["block"+init].hitTest(_x+30, _y+48)) and jump == false) {
  9.             gravity = gravityval;
  10.             moy = 0;
  11.             jumpcount = 0;
  12.         }
  13.     }...
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1828
  • Loc: In the Great White North

Post 3+ Months Ago

did you get this figured out? If not I think there are a few namespace problems that you might need to resolve. I'm pretty sure that both "init" and "stage" are reserved words in the Flash IDE so that could be causing some problems for you.

Instead try
Code: [ Select ]
onClipEvent (enterFrame) {
  for (i=1; i<=10; i++) {
    if (_root.newClipName["block"+i].hitTest(_x+30, _y+48)) {
      gravity = 0;
      jump = false;
      jumpcount = 0;
    }
    if (!(_root.newClipName["block"+i].hitTest(_x+30, _y+48)) && jump == false) {
      gravity = gravityval;
      moy = 0;
      jumpcount = 0;
    }
  }...
  1. onClipEvent (enterFrame) {
  2.   for (i=1; i<=10; i++) {
  3.     if (_root.newClipName["block"+i].hitTest(_x+30, _y+48)) {
  4.       gravity = 0;
  5.       jump = false;
  6.       jumpcount = 0;
  7.     }
  8.     if (!(_root.newClipName["block"+i].hitTest(_x+30, _y+48)) && jump == false) {
  9.       gravity = gravityval;
  10.       moy = 0;
  11.       jumpcount = 0;
  12.     }
  13.   }...


There may be other problems too but they're had to track down since I can't see the rest of your code.

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 12 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.