Ask a Question related to Macromedia Exchange Dreamweaver Extensions, Design and Development.

  1. #1

    Default Nested Functions

    I am trying to use nested functions in a floater i am building, and right after
    I edit the js document and reload dreamweaver the functions work, but if I
    reload dreamweaver again without making any changes to the file it says the
    nested function does not exist. Can anyone help me figure this out? Thanks

    Clukey Guest

  2. Similar Questions and Discussions

    1. #40765 [NEW]: calling backtrace inside nested static class functions causes segfault
      From: ndroege at bimp dot de Operating system: linux debian PHP version: 5.2.1 PHP Bug Type: Reproducible crash Bug...
    2. Nested classes?
      Hi I'm following the blog reader example in the 2nd chapter of the 'Developing Rich Clients with Macromedia Flex' book, but using Flex Beta 2. ...
    3. Nested Forms?
      Hi I'm still working on my diploma. And I'm just getting started with CF. I have a regular form. In this form I integrated a Flashform. How can I...
    4. hittest: nested MCs
      I have multiple dynamically duplicated objects, called "units". Let's say I have 2 at the point this code is executed: ...
    5. #10743 [Com]: class functions & PHP core functions inconsistently clash ;)
      ID: 10743 Comment by: destes at ix dot netcom dot com Reported By: jjones at net-conex dot com Status: Open...
  3. #2

    Default Re: Nested Functions

    Exit DW and try deleting the cache fle located in the configuration folder. Then open dreamweaver and try the floater, but don't reload it, just restart it and see if it makes a difference.
    envision3d Guest

  4. #3

    Default Re: Nested Functions

    That works the first time also, but as soon as I restart DW it has recreated
    the cache file so it stops working again. So, I would have to delete the cache
    file every time I exit dreamweaver for that to work.

    Clukey Guest

  5. #4

    Default Re: Nested Functions

    What do you mean by "nested functions"?

    Randy

    > I am trying to use nested functions in a floater i am building, and right after
    > I edit the js document and reload dreamweaver the functions work, but if I
    > reload dreamweaver again without making any changes to the file it says the
    > nested function does not exist. Can anyone help me figure this out?
    Randy Edmunds Guest

  6. #5

    Default Re: Nested Functions

    For Example:

    number1.number2()



    function number1() {
    function number2() {
    alert("this is function number 2")
    }
    }
    Clukey Guest

  7. #6

    Default Re: Nested Functions

    Why are you doing a nested function? Why not just create 2 seperate functions and call one of the functions inside the other.
    envision3d Guest

  8. #7

    Default Re: Nested Functions

    Because I need two versions of most every function. What I mean is if a=b then
    I have to use a different set of functions then if a=c; and both sets of
    functions accomplish the same goal, but they have to do it in different ways.
    And since I would rather not have to go through every function and put that IF
    statement, I just nested them and call the one I need.

    Clukey Guest

  9. #8

    Default Re: Nested Functions

    Would an overloaded function be useful? I honelsty have never used or have experience with nested functions. Sorry I couldn't be of more help.
    envision3d Guest

  10. #9

    Default Re: Nested Functions

    What do you mean an "overloaded" function?
    Clukey Guest

  11. #10

    Default Re: Nested Functions

    An overloaded function is are functions that have the same name but different
    input parameters list. like:

    function tellMeAJoke()
    {
    arguments
    }

    function tellMeAJoke(int a, int b)
    {
    arguments
    }

    function tellMeAJoke(string a, string b)
    {
    arguments
    }

    As you can see each funtion has the same name and will perform the same taks,
    but based on the different input parameters. If I didn't explain it well
    enough, you good do a google search for overloaded functions. Maybe someone
    else could explain it better than me.


    envision3d Guest

  12. #11

    Default Re: Nested Functions

    I just noticed that you might be calling your nested function incorrectly. You
    just have to call the container function. So if you had your function:

    function number1() {
    function number2() {
    alert("this is function number 2")
    }
    }

    simply call number1()

    Have a peak at this link:

    [url]http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Functions#Nes[/url]
    ted_functions_and_closures


    envision3d Guest

  13. #12

    Default Re: Nested Functions

    I didn't know about overloaded functions, thanks, but I don't think that would
    help because the functions basically have the same args they just have parse
    the data differently.

    If I simply called number1() it would not run number2() because all functions
    have to be called specifically, as with the link you gave, the container
    function always called the nested function. Also, I know it is possible to use
    number1.number2() because they work fine right after I edit the file.

    Clukey Guest

  14. #13

    Default Re: Nested Functions

    What if you were to create a function that would check your values and return
    true or false. Something like:

    function checkValues(a, b, c)
    {
    arguments
    return whatever;
    }

    Then have your two functions. Then in your code just say something like:

    if (checkValues(a,b,c) == something)
    {
    perform this function
    }else{
    perform the other function
    }

    I know you are using nested functions for a specific reason, but I am just
    trying to help you find a way around this problem you are having with the
    nested function.

    Have you done a test? Maybe create a very simple behavior and use a nested
    function. See if you have the same problem with that nested function as well.
    If not, then there may be something else causing the problem.

    envision3d Guest

  15. #14

    Default Re: Nested Functions

    Thanks, the reason I am using nested functions is because I already have half
    the functions built for this extension and I didn't want to have to go through
    all 39 (give or take) functions and put a huge "if", it would take too long and
    make the code harder to read, so I thought nesting them would be the easiest.

    My other option I have thought might work is to have my code like this,

    function number1(f, [arg1, arg2, ...])
    switch(f) {
    case 1:
    number2();
    break;
    case 2:
    number3(arg1, arg2, ...)
    break;
    }
    function number2() {
    ...
    }
    function number3() {
    ...
    }

    Then call number1(...)

    But I was really hoping to get the nested functions working because it would
    still be easier and simpler, but if there is any other better way to do this I
    would be fine with that.

    I made a simple command that would just alert something, and the nested
    function didn't work, so maybe dreamweaver doesn't support them, but I still
    can't figure out why it works in the floater right after I edit the file.

    Clukey Guest

  16. #15

    Default Re: Nested Functions

    Clukey,

    I don't know what is your "comfort zone" or level of experience working with
    javascript coding.

    As for your quoted statement, "...so maybe dreamweaver doesn't support
    them...", you know Dreamweaver is ideally a HTML authoring app. That is to say,
    you know some fundamentals of HTML and understand how it works, then your skill
    become more intitution with HTML works and what's not. With understanding of
    how HTML works, and that you would be able to "troubleshoot" when HTML acts up
    or why it doesn't work as intended.

    That analogy with javascript as opposed to HTML, to code javascript, you need
    to have some fundemantals of javascript coding. The more comfort zone and
    knowledge, as well as hands-on coding with javascript will definitely be of an
    asset to you to develop some javascript code to perform specific task you want.

    So if javascript coding is totally new enviornment for you, perhaps you want
    to go this route with possible two ways: search engine or book(s).

    Have you tried to do a bit of research using Google or Yahoo to locate some
    possible tutorial and step by step? Or you might want to consider to buy a book
    about javascript. There are pretty darn good number of good books covering
    javascript.

    Hope that helps, no? Cheers, DWD (Brian)

    Deaf Web Designer Guest

  17. #16

    Default Re: Nested Functions

    Thanks for the advice, but javascript is by no means new to me. Although thats
    not to say I know all there is to know, as I am sure I sometimes don't do
    things in the most "proper" or efficient way, but I am more than competent in
    the language.

    What I have found out in recent learning is that calling a nested function in
    the manner "function1.function2()" actually is not supported within javascript
    itself, the reason I thought it was is that when I was first making my
    extension I was using Dreamweaver MX and for some reason it worked flawlessly.
    Although, now having upgraded to version 8 I realize they don't work quite as I
    thought.

    Now what I am looking for is sort of a "best practices" help from other
    experienced javascripters on how to create two sets of functions with the same
    goal yet different methods of getting to that goal. And as I have already
    created one of the sets I would rather not have to do something to every
    function, and I was hoping there was a broader way of going about this.

    Any help that can be provided on this would be much appreciated.

    Clukey Guest

  18. #17

    Default Re: Nested Functions

    Are you trying to call these from your main floater code? In your example,
    number2 is a local function that will only work from inside number1.



    --
    Tom Muck
    co-author Dreamweaver MX 2004: The Complete Reference
    [url]http://www.tom-muck.com/[/url]

    Cartweaver Development Team
    [url]http://www.cartweaver.com[/url]

    Extending Knowledge Daily
    [url]http://www.communitymx.com/[/url]


    "Clukey" <webforumsuser@macromedia.com> wrote in message
    news:esa7e7$m4n$1@forums.macromedia.com...
    > For Example:
    >
    > number1.number2()
    >
    >
    >
    > function number1() {
    > function number2() {
    > alert("this is function number 2")
    > }
    > }

    Tom Muck Guest

  19. #18

    Default Re: Nested Functions

    Right, I realized that just recently, because originally I was using
    Dreamweaver MX to make my extension and it actually worked. So, now I have 8
    and it doesn't work so I looked into it and realized that can't be done. Thanks

    Clukey Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139