Actionscript 2.0 Functions problem

Posted by Joshua on Stack Overflow See other posts from Stack Overflow or by Joshua
Published on 2010-05-29T14:00:22Z Indexed on 2010/05/29 14:02 UTC
Read the original article Hit count: 247

I have two problems.

The first problem is with the following functions; when I call the function in (enterFrame), it doesn't work:

onClipEvent (load) {

 function failwhale(levelNum) {
  _root.gotoAndStop("fail");
  failFrom = levelNum;
 }

 function guardSightCollision(guardName, guardSightName) {
  if (_root.guardName.guardSightName.hitTest(_x, _y+radius, true)) {
   failwhale(1);
  }
  if (_root.guardName.guardSightName.hitTest(_x, _y-radius, true)) {
   failwhale(1);
  }
  if (_root.guardName.guardSightName.hitTest(_x-radius, _y, true)) {
   failwhale(1);
  }
  if (_root.guardName.guardSightName.hitTest(_x+radius, _y, true)) {
   failwhale(1);
  }
 }
}
onClipEvent (enterFrame) {
 guardSightCollision(guard1, guard1Sight);
}

Why doesn't it work?...

The second problem lies in the failFrom variable:

function failwhale(levelNum) {
    _root.gotoAndStop("fail");
    failFrom = levelNum;
}

How do I make failFrom a "global" variable in that it can be accessed anywhere (from actionscript in frames and even movieclips)...Right now, when I try to trace failFrom in a different frame, it is "undefined".

© Stack Overflow or respective owner

Related posts about oop

Related posts about function