Actionscript class member function calling problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • strongfrakk
    New Member
    • Feb 2007
    • 2

    Actionscript class member function calling problem

    Hi All, I have problem with subject .(
    The code seems like good.

    For example:
    cmenu.as
    Code:
    class cmenu
    {
      public var menuitemarray;
    
      public function cmenu{menuitemarray=new Array;}
    
      public function loadxml() {
        var omenuitem = new cmenuitem();
        this.addmenuitem(omenuitem);
         }
    
      public function addmenuitem(omenuitem_param:cmenuitem){
         this.menuitemarray.push(omenuitem_param);
       }
    
    }
    
    [B]cmenuitem.as[/B]
    class cmenuitem{}
    
    [B]maintimeline[/B]
    var omenu = new cmenu();
    omenu.loadxml();
    --------------------------------------
    The addmenuitem doesnt get called , why ?
    Are there any notable thing in class member function calling ?

    PS:I use Flash 8
    Thanks in advance!
    Csaba
    Last edited by Motoma; Feb 22 '07, 03:45 PM. Reason: Added [CODE ] [ /CODE] Brackets
  • strongfrakk
    New Member
    • Feb 2007
    • 2

    #2
    As I see I need to qutation the original code

    class CMenu {
    public var aoMMCollection;//array for MM - main menu items
    ...
    ...
    public function LoadXML(sXML_:S tring)
    {
    aoMMCollection = new Array();
    ...
    ...
    var oMMtmp = new CMM();
    trace(typeof(oM Mtmp)); // outputbject
    trace("before push"); // output:before push
    AddMainMenu(oMM tmp);
    ...
    ...
    }// end of public function LoadXML(sXML_:S tring)
    ...
    ...
    public function AddMainMenu(oMM _:CMM)
    {
    trace("push MM"); // output:nothing ............... ........!
    this.aoMMCollec tion.push(oMM_) ;
    }
    }//end CMenu class

    maintimeline ............... ............... .........
    var oMenu:CMenu = new CMenu("logtext" );
    oMenu.LoadXML(" ./menu.xml");

    result ............... ............... ...........
    AddMainMenu doesn't get called


    That is all I know about this

    Comment

    • stolkco
      New Member
      • Aug 2007
      • 2

      #3
      I am having the same kind of problem.

      One class in my project has member functions which are callable from within
      other member functions in that class.
      Another class in my project has member functions that seem unaccessible from functions within that particular class.

      I really have no idea why.

      Comment

      • stolkco
        New Member
        • Aug 2007
        • 2

        #4
        I'm beginning to get a clue: the method from which I'm trying to call 'sibling' member functions is used as an eventhandler.
        Apparently it's context is lost when it is called.

        To make things more clear: I'm working on a scorm course (the learning interactions stuff) I've extracted some of the code of the MultipleChoice library object and moved it into a class in an actionscript file. Including the onMCButton function. This onMCButton function seems to be used as an eventhandler; anyway the function is passed as an argument:
        router.initCont rolButton(onMCB utton). Since I've created a MultipleChoice class instance myMC this 'registration ' has become router.initCont rolButton(myMC. onMCButton)
        From within the onMCButton function the reference to the class instance is gone, subsequent calls to other functions like evalMC etc fail.
        To be able to get things working I'm using a static member var to hold the data, and I recreate the MultipleChoice object within the onMCButton function. Might have made all functions static too...

        Comment

        Working...