Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function foulups :0

Status
Not open for further replies.

Chris99

Technical User
Jan 11, 2001
18
CA
Hi everyone - hope some kind and wise person can figure this one out ;)!

I'm trying to optimize my code by using what I call 4 "BIG" functions lol - that is, functions that include many parameters(one of them has 9 and works OK).

Problem is that though I got three working fine, the 4th one just wont work.

I always ensure my functions are created on the mainstage. That way, I can easily invoke them by just typing into my code, for example,

_root.funcOne(x,y,z);

Purpose of function: if an object (mcA in which the function is invoked) hitTests another object (mcB) and mcB's variable zz is true, then mcA's variable Alert goes True, in which case mcA is deleted (mcA being a duplicated mc).

Below please find the original source code "behind" the problem function .... and right below that I have placed the actual function I created on the mainstage. Also, finally, I tyed in how I invoke that function. Problem is that the critical variable "alert" (parameter C) just wont go true. This function is invoked on 8 similar MC's, within onClipEvent(enterFrame), as are the other 3 which work fine.

ORIGINAL SOURCE CODE that existed in all 8 MC's prior to being replaced by the function:

if(this.hitTest(_root["e"+h]) && _root["e"+h].zz==true){alert=true};
if(this.hitTest(_root["d"+h]) && _root["d"+h].zz==true){alert=true};
if(this.hitTest(_root["c"+h]) && _root["c"+h].zz==true){alert=true};
if(this.hitTest(_root["b"+h]) && _root["b"+h].zz==true){alert=true};
if(this.hitTest(_root["a"+h]) && _root["a"+h].zz==true){alert=true};

FUNCTION:
function alertWatch(a,b,c){
if(a.hitTest(_root["e"+b]) && _root["e"+b].zz==true){c=true};
if(a.hitTest(_root["d"+b]) && _root["d"+b].zz==true){c=true};
if(a.hitTest(_root["c"+b]) && _root["c"+b].zz==true){c=true};
if(a.hitTest(_root["b"+b]) && _root["b"+b].zz==true){c=true};
if(a.hitTest(_root["a"+b]) && _root["a"+b].zz==true){c=true};
}

HOW ABOVE FUNCTION IS INVOKED:

_root.alertWatch(this,h,alert);

(h is a variable within each MC that corresponds to an
_x coordinate. All other 3 functions have this same
paramter.

Since the function is invoked in an "enterFrame" environment, it should be continuously running I presume.

Sorry this is long-winded. Any insights would be appreciated, thanx in advance :) !

I want to Learn :D !!
 
Well, I managed to figure this one out myself after all. And for those who are curious, here's the solution:

The function had to be written thusly.

function alertWatch(a,b){
if(a.hitTest(_root["e"+b]) && _root["e"+b].zz==true){a.alert=true};
if(a.hitTest(_root["d"+b]) && _root["d"+b].zz==true){a.alert=true};
if(a.hitTest(_root["c"+b]) && _root["c"+b].zz==true){a.alert=true};
if(a.hitTest(_root["b"+b]) && _root["b"+b].zz==true){a.alert=true};
if(a.hitTest(_root["a"+b]) && _root["a"+b].zz==true){a.alert=true};
}

Replacing the variable "alert" with the parameter c was unncecessary. "alert" works in the scope of this function. Thus I removed the "c" parameter, changed "c=true" to "this.alert=true" and it works fine now. Bye for now.


I want to Learn :D !!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top