7 Replies Latest reply on Feb 14, 2007 12:24 AM by Dave.Hollings

    Calling and Creating Functions

    Dave.Hollings Level 1
      Hi all,

      Wondering if someone could shed some light on my situation. I am writing some actionscript within my flash project. My stage has 2 main mc (menu_mc, and homewin_mc).

      menu_mc contains 6 layers, each layer has one button on it. There is some motion tweening for each button and a further layer containing the following actionscript.

      stop();
      // ---- Start of Menu ActionScript ----
      personal_btn.onRelease = function() {
      _global.nextpage = "personal";
      function1();
      };
      // ---- End of Menu ActionScript ----

      I want the above script to do the following: When a user click the personal_mc button it assigns a value to the global variable nextpage, then call a function.

      homewin_mc contains 4 layers. 2 layers contains motion tweening, 1 layer is for labels where I have home-in and home-out and the other is for stop actions.

      The main timeline has the following actionscript in the action layer:
      ]// ---- Start declaration of Global vars ----

      _global.nextpage="";

      // ---- End declaration of Global vars----

      // ---- Start declaration of Global functions ----

      _global.function1 = new function() {
      homewin_mc.gotoAndPlay("home-out");
      gotoAndPlay(_global.nextpage);
      };

      // ---- End declaration of Global functions ----

      When the button has been released and the function has been called I need the code to play from a frame label (home-out) within the homewin_mc movie clip. After it has played this I need the function to read the value assigned to nextpage global var and then gotoAndPlay this frame label.

      If anyone is able to help it would be very much appreciated.
        • 1. Re: Calling and Creating Functions
          Jan-Paul K. Level 1
          is your function1 getting called once you click on the button? (put a trace in there to see if it is)
          you might want to add a full reference to the homewin_mc in there like "_root.homewin_mc"...

          Try tracing the homewin_mc in the function1 to see if it is undefined or not:
          trace(homewin_mc);
          if this returns "undefined" when you test the movie try
          trace(_root.homewin_mc);
          • 2. Re: Calling and Creating Functions
            Dave.Hollings Level 1
            Thanks for the reply,

            I am getting a undefined when testing, before clicking the button. Is my syntax correct? and can the coding be written on the main timeline, under the action layer? Would this make it easier to debug if required?

            When I click the button it does not seem to be doing anything at all. I have placed a trace for function1 on the main timeline under the function1 script. I have also placed a trace on the homewin_mc within the function1 script.

            Nothing has been passed back to the output windows apart from the initial undefined. Any ideas?
            • 3. Re: Calling and Creating Functions
              Jan-Paul K. Level 1
              please try this code and post the complete trace outout here.
              • 4. Re: Calling and Creating Functions
                Dave.Hollings Level 1
                I assume that the code you supplied was to be inserted within my menu_mc timeline and not the main timeline. If this is correct please find the complete trace below.

                the button movie is: _level0.menu_mc.personal_btn
                Button was pressed
                trying to call function: undefined
                • 5. Re: Calling and Creating Functions
                  Jan-Paul K. Level 1
                  ok, so the function is not correctly defined.

                  Change the function declaration to

                  function function1() {
                  trace("function1 has been called");
                  trace("will goto and play in MC: "+homewin_mc);
                  homewin_mc.gotoAndPlay("home-out");
                  trace("will jump to frame-marker with name "+_global.nextpage+" in main timeline");
                  _root.gotoAndPlay(_global.nextpage);
                  };

                  and put it in the root timeline.

                  then change the lines in the onRlease event handler to
                  trace("trying to call function: "+_root.function1);
                  _root.function1();
                  • 6. Calling and Creating Functions
                    Dave.Hollings Level 1
                    Ok sorry its taken a while to get back, PC when on the blink. I have made the changes and now the complete trace report is as follows. As far as I can tell the button is doing its job, and the function is doing 50% of its job. Within the homewin_mc there is a tween kind of a transition which needs to play half way through the function1 routine. This is not happening - any ideas or suggestions!

                    the button movie is: _level0.menu_mc.personal_btn
                    Button was pressed
                    trying to call function: [type Function]
                    function1 has been called
                    will goto and play MC: undefined
                    will jump to frame-marker with name personal in main timeline
                    • 7. Re: Calling and Creating Functions
                      Dave.Hollings Level 1
                      Sorry to push this just wondering if anyone had any further help, its still does not work.