A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Function Question?

  1. #1
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976

    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

  2. #2
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    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?

  3. #3
    Senior Member Ex-Ess's Avatar
    Join Date
    Nov 2002
    Location
    York (England)
    Posts
    588
    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

  4. #4
    Who needs pants? hooligan2001's Avatar
    Join Date
    Apr 2001
    Location
    Somewhere
    Posts
    1,976
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center