dcsimg
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Function call - Problems

  1. #1
    live? gangsta?
    Join Date
    May 2006
    Posts
    14

    Function call - Problems

    Hi there,

    I'm working on a little flash project and I've got a big problem. I tried to call an other function(functionB) in a function (functionA). FunctionA is a child of abc.def. FunctionB is a child of abc.

    Code:
    abc = new Object 
    abc.def = new Object
    
    abc.def.ghi = function () // functionA
    {
    abc.cba ()
    }
    
    abc.cba = function () // functionB
    {
    trace ( "hi" )
    }
    
    abc.def.ghi ()
    But I simply get an error:
    cba() is not a method of Undefined variable on line 6 abc.cba ()
    I don't know what's wrong and I hope you can help me.

  2. #2
    Senior Member
    Join Date
    Dec 2006
    Posts
    274
    Well, you try to "use" abc.cba() before it is declared. Define abc.cba before abc.def.ghi and it should run ok..

  3. #3
    Member
    Join Date
    Nov 2002
    Posts
    67
    I am probably wrong, but try using abc_cba() instead of abc.cba().

    The compiler might think that this is the . before a method, like

    myvariable = element ("My Element")
    myvariable.show()

    Just a thought, but like I said, maybe not an accurate thought.

  4. #4
    live? gangsta?
    Join Date
    May 2006
    Posts
    14

    Perhaps...

    Perhaps the compiler thinks that every variable in a function which is defined to an object is a property of this object.

    Example:
    Code:
    abc = new Object;
    
    abc.def = function () {
    
    myvar = 17
    
    }
    The compiler:
    'myvar' is a property of the object abc

    Code:
    abc.myvar = 17
    ---

    The problem is that if you try to call a function, the compiler does the same as in the 'myvar'-example:

    Code:
    ...
    abc.def.ghi = function () // functionA
    {
    abc.cba ()
    }
    ...
    The compiler:
    abc.cba() is a property of abc.def

    Code:
    abc.def.abc.cba()
    ---

    Then I thought I can use 'root' to solve this problem. But maybe there is a bug in the compiler which does the following:

    Code:
    abc.def.ghi = function () // functionA
    {
    root.abc.cba ()
    }
    The compiler:
    root.abc.cba() is a property of abc.def

    Code:
    abc.def.root.abc.cba()
    ---

    I'm not sure but it sounds possible to me.

  5. #5
    Senior Member
    Join Date
    Dec 2006
    Posts
    274
    This seems to be visibility issue, somehow if you call abc.cba() from abc.def.ghi() it cant see abc.cba.. no matter if you use root.abc.cba() or whatever..

    However little less deep function hierarchy seems to work:

    Code:
    abc = new Object; 
    
    abc.cba = function() // functionB
    {
    trace ( "hi" );
    }
    
    abc.ghi = function() // functionA
    {
    this.cba();
    }
    
    //-----------------
    trace ( "start" );
    abc.cba();
    abc.ghi ();
    trace ( "end" );
    In this case keyword this point to abc object,...

  6. #6
    live? gangsta?
    Join Date
    May 2006
    Posts
    14
    Ok, looks like I can't call any function outside of the object that has got this function. Seems to be a bug...

    However, now I must rewrite my entire code.

    Nevertheless thanks to everyone for the help!

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