7 Replies Latest reply on Apr 16, 2011 2:30 PM by Ned Murphy

    How to access functions

    firesoul7468ollie

      Hey,

       

      thing_btn.addEventListener(MouseEvent.CLICK, clicked);

      thing2_btn.addEventListener(MouseEvent.CLICK, clicked2)

       

      function clicker(event:MouseEvent) {

      trace("hey");

      }

      function clicker2(event:MouseEvent) {

      clicker(event:MouseEvent);

      }

      with the code above how would you call the function clicker from the function clicker2?
      as with the code i have it comes up with the error "1084: Syntax error: expecting rightparen befor colon"
      thanks:)

        • 1. Re: How to access functions
          Ned Murphy Adobe Community Professional & MVP

          I'd use:

           

          clicker(event);

           

          But if the intention is that thing2_btn will trigger clicker2, you missed that via misspelling.  YOur event listeners are calling differently named functions.

          1 person found this helpful
          • 2. Re: How to access functions
            firesoul7468ollie Level 1

            ah yes my mistake

             

            the clicker(event) does not seem to work for KeyboardEvents..

             

            so i have

             

            stage.addEventListener(KeyboardEvent.KEY_DOWN, spaceDown)

             

            function spaceDown(event:KeyboardEvent){

            pressed++;

            if(event.keyCode == 32){

            moverTimer.stop();

            }

            whichLine="Line"+String(pressed)

            trace(whichLine)

            moverTimer.start();

            }

             

            and i need to call spaceDown first

             

            spaceDown(event);

             

            and that comes up with the error

             

            1120:access of undefined property event

            • 3. Re: How to access functions
              Ned Murphy Adobe Community Professional & MVP

              If you are only showing a portion of your code, it's not clear what you are trying to do.  If you are trying to send a MouseEvent to a function that is looking for a KeyBoardEvent, that would produce an error.  But I don't think it would be the one you say you are getting, so that one may be waiting in line for you to resolve whatever you've done to get the error regarding "event"

              1 person found this helpful
              • 4. Re: How to access functions
                firesoul7468ollie Level 1

                stop();

                spaceDown(event)

                 

                var whichLine:String;

                var c1:Number = 0;

                var c2:Number = 1;

                var c3:Number = 2;

                 

                var starter:Number;

                var ender:Number = 57

                var pressed:Number = 1

                 

                var moverTimer:Timer=new Timer(1000);

                moverTimer.addEventListener(TimerEvent.TIMER, this[whichLine]);

                moverTimer.start();

                 

                stage.addEventListener(KeyboardEvent.KEY_DOWN, spaceDown)

                 

                function spaceDown(event:KeyboardEvent){

                pressed++;

                if(event.keyCode == 32){

                moverTimer.stop();

                }

                whichLine="Line"+String(pressed)

                trace(whichLine)

                moverTimer.start();

                }

                 

                 

                function Line1(event:TimerEvent) {

                trace("Line1")

                starter = 1

                c1++;

                c2++;

                c3++;

                removeColor();

                if(c1==8){

                c1=1

                }

                if(c2==8){

                c2=1

                }

                if (c3==8) {

                c3=1

                }

                this["box"+c1].gotoAndStop(2);

                this["box"+c2].gotoAndStop(2);

                this["box"+c3].gotoAndStop(2);

                }

                 

                function Line2(event:TimerEvent){

                trace("line2")

                }

                 

                function removeColor() {

                for (var i:Number = starter; i<ender; i++) {

                this["box"+i].gotoAndStop(1);

                }

                }

                 

                this is my full code

                 

                and i need spaceDown(event) to call on the function spaceDown so that whichLine is given what line it is on which then calls on the function Line1 or Line 2

                • 5. Re: How to access functions
                  Ned Murphy Adobe Community Professional & MVP

                  The error is correct, you are trying to call a function using an argument that is not defined...

                   

                  stop();

                  spaceDown(event)  <--- there is no such thing as event at this stage of the program

                  1 person found this helpful
                  • 6. Re: How to access functions
                    firesoul7468ollie Level 1

                    It does not matter if i put it at the end of the code though =/

                     

                    thanks for your help so far

                    • 7. Re: How to access functions
                      Ned Murphy Adobe Community Professional & MVP

                      The only place it will work for you is if you put it somewhere where event is defined, which so far is only inside your functions.  If you want to call the spaceDown function without actually using the keyboard you can change the code to be....

                       

                      function spaceDown(event:KeyboardEvent=null){

                      pressed++;

                      if(event.keyCode == 32){

                      moverTimer.stop();

                      }

                      whichLine="Line"+String(pressed)

                      trace(whichLine)

                      moverTimer.start();

                      }

                       

                      spaceDown();

                       

                      but then your code inside the function wil have another error since it tries to use the event object, which will be null.

                       

                      Your first posting made some sense in terms of what you were asking, but you seem to have twisted what you were asking and applied it to implementing something totally different.  I can't say I know what you're up to at this point.  You probably need to step back and try to reason things out.