A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Optional Parameters

Hybrid View

  1. #1
    Member
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    76

    Optional Parameters

    Hi all,

    I've got a simple question:
    is it possible in 3DFA to give your functions optional parameters?

    Code:
    // c shall be the optional parameter
    
    function myFunction(a,b,c) {
       trace (a,b);
       trace (a,b,c);
    }
    
    myFunction(1,2,3); // everthing is ok...
    myFunction(1,2); // 3DFA shows an error
    Error:
    function myFunction(a,b,c) was given 2 parameters when 3 were expected on line 9 myFunction(1,2)


    Anyone knows how to solve this?

    Thanks,
    leifi

  2. #2
    Senior Member kusco's Avatar
    Join Date
    Nov 2001
    Posts
    681
    .. correction added ..
    Last edited by kusco; 08-06-2007 at 10:35 AM.
    Cheers,
    kusco
    (3DFA Support Team)

  3. #3
    Senior Member
    Join Date
    Dec 2006
    Posts
    274
    It is bit mixed bag.. if you supply only 2 params then you have to check if 3.rd one is null, if you have to check it then it is no pain to supply 3.rd parameter as null

    However, function overloading could be more useful, you could define 2 same-name functions to work with 2 or 3 params.... but then it is only visual cleaniness as you define myFunc(a,b) and myFunc(a,b,c)... so why not just do it old fashion way myFunc1 and myFunc2

    At the moment 3dfa does not accept multiple same name functions so... there is no much to do for now.

    edit: I was slow
    Last edited by Finjogi; 08-06-2007 at 05:25 AM.

  4. #4
    Senior Member kusco's Avatar
    Join Date
    Nov 2001
    Posts
    681
    The next release of 3DFA, due later this week, allows the use of optional parameters for functions - for both Flash 8 and 9 export.

    You can define a function ...

    function my_function (a, b=42, c="hello", d=true)
    {

    }

    ... and you can specify between one and four parameters when calling the function.
    Cheers,
    kusco
    (3DFA Support Team)

  5. #5
    Member
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    76
    Cool! Thank you for this fast response!
    Maybe I have some more ideas for 3DFA...

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