|
-
Who needs pants?
Function Question?
i have a function called moveArr
function = moveArr(){
i was just wondering you know the space in the function between the brackets how do i use that. Is it to declair varibles that are used in the function. And once i have declaired them how do i access them.
Is it anything like
Code:
function = moveArr(dir){
if(dir == right){
//do things
}
}
on a button
Code:
on(release) {
moveArr(right);
}
just trying to work out how it works 
ThankS in AdvancE
[h]ooligan
-
Who needs pants?
And also what happens if i have 2 varibles
eg
Code:
function = moveArr(x,y){
}
how do i set each of these varibles and how do i use them in the function?
-
Senior Member
You're right. Between the brackets you put the vars you want to pass to the function.
say you have four buttons, left, right, up and down. You colud use:
//LEFT BUTTON
on(release) {
moveArr(-1,0);
}
//RIGHT BUTTON
on(release) {
moveArr(1,0);
}
//UP BUTTON
on(release) {
moveArr(0,-1);
}
//DOWN BUTTON
on(release) {
moveArr(0,1);
}
Then somewhere in your movie (usually first frame) you would have the actual function:
function = moveArr(x,y){
object._x += x;
object._y += y;
}
This would move an object depending on which button was activated because you are sending either 0,1 or -1 to the function and then calling it using x or y depending on the button. The function just moves the object both ways whenever the function is called but won't appear to move if one of the vars passed was 0.
does that help?
Think I rambled a bit at the end
-
Who needs pants?
Thanks Heaps for that really appretiate it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|