View Full Version : creating functions
deathcloud33
06-06-2005, 01:50 AM
right now I have the following code to create a function I am making:
this.checkhits() = function(objects){
for(x=0;x<=objects-1;x++){
if(this.hits[x]){
return(1);
}
}
}
and It claims that that needs to be in an onClipEvent handler. does anyone know the correct way to initialize a function?
senocular
06-06-2005, 01:58 AM
this.checkhits = function(objects){ ...
deathcloud33
06-06-2005, 02:12 AM
that doesn't work either...
D=
**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 1: Statement must appear within on/onClipEvent handler
this.checkhits = function(objects){
Total ActionScript Errors: 1 Reported Errors: 1
senocular
06-06-2005, 02:14 AM
make sure you have nothing on the screen selected
deathcloud33
06-06-2005, 02:18 AM
what?
oh, like have it on the frame?
oh, I had it on the movieclip...
senocular
06-06-2005, 02:20 AM
if you have code *on* a movie clip, it needs to on/onClipEvent handlers like your error statement suggested
deathcloud33
06-06-2005, 02:26 AM
argh.
that's annoying.
now it's not working, but I can't tell how.
and no errors. oh well. D=
deathcloud33
06-06-2005, 02:38 AM
okay, now my function won't return anything.
whenever I trace(checkhits(2)); it just displays undefined.
the AS for the function is now:
checkhits = function(objects){
y=0;
for(x=0;x<=objects-1;++x){
y+=hits[x];
}
return y;
}
senocular
06-06-2005, 02:46 AM
for 1, you should define y with var since you want it to be local to that function. Then, you need to figure out where hits is and reference it correctly
checkhits = function(objects){
var y=0;
for(var x=0; x <= objects-1; ++x){
y+= this.hits[x]; // this?
}
return y;
}
deathcloud33
06-06-2005, 05:47 AM
ah, thanks alot.
I still have a long way to go, it seems.
I'll try that out.
EDIT: nope, still doesn't work.
deathcloud33
06-06-2005, 10:34 PM
still need help.......
deathcloud33
06-06-2005, 10:38 PM
sorry for so many posts, but I am also wondering if there is a way to get the dimensions of an array mid-execution.
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.