multiple hittests in action script with "for"

  • rejoin
  • Born
  • Born
  • No Avatar
  • Joined: Nov 30, 2009
  • Posts: 1
  • Status: Offline

Post November 30th, 2009, 3:32 pm

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
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post November 30th, 2009, 3:32 pm

  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Joined: Jul 11, 2005
  • Posts: 1828
  • Loc: In the Great White North
  • Status: Offline

Post December 7th, 2009, 8:21 pm

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.
If at first you don't succeed F1... If that doesn't work try Google!
//// Designer, Developer & Teacher - Interactive, Motion and 3D \\\\
Portfolio at WhenImNotSleeping.com

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 53 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
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.