23 Replies Latest reply on Jul 25, 2007 6:43 AM by kglad

    onRelease function not working

    Seraya
      Hi everyone,

      I have the following code on frame 1 of the main timeline:

      this.categoryIndex_mc.indexBack_mc.backToIndex_btn.onRelease = function ():Void {
      trace("button pressed");
      oIntervalIDs[garmentSlides_mc._name] = setInterval(fadeMovieClip, 0, garmentSlides_mc, 5);
      new Tween(categoryIndex_mc, "_y", null, 412, 107, 3, false);
      categoryIndex_mc.indexBack_mc.gotoAndStop("chooseText");
      }

      When I test the movie I get the hand cursor appear when I rollover the button indicating that it is in fact a button but when I press and release it, none of the code works. I added the trace statement to see what was going on but again when testing it the output window doesn't appear.

      Can someone tell me if there's something wrong with the code? The following is the entire code on frame 1 of the main timeline.

      Appreciate any help offered.



      CODE

      //-----------Initialization---------\\
      import mx.transitions.Tween;
      this.categoryIndex_mc._alpha = 0;
      this.garmentSlides_mc._alpha = 0;
      //-----------------------------------\\

      //-----------Introductory animation plays---------\\

      intro_mc.onEnterFrame = function () {
      this.play();
      delete intro_mc.onEnterFrame;
      }
      //-----------------------------------\\


      //-----------Category list fades in---------\\

      var oIntervalIDs:Object = new Object();

      function fadeMovieClip (mClip:MovieClip, nRate:Number):Void {
      if(mClip._alpha >= 0 && mClip._alpha < 100) {
      var nAlpha:Number = mClip._alpha;
      mClip._alpha = nAlpha + nRate;
      updateAfterEvent();
      }
      else {
      clearInterval(oIntervalIDs[mClip._name]);
      }
      }

      oIntervalIDs[categoryIndex_mc._name] = setInterval(fadeMovieClip, 100, categoryIndex_mc, 5);

      categoryIndex_mc.onEnterFrame = function () {
      if(categoryIndex_mc._alpha > 95) {
      this.indexBack_mc.gotoAndPlay("chooseText");
      delete categoryIndex_mc.onEnterFrame;
      }
      }

      //-----------------------------------\\


      //-----------Slideshow fades in, category index slides out, playhead jumps "back to index" frame ---------\\

      cat_btn.onRelease = function ():Void {
      oIntervalIDs[garmentSlides_mc._name] = setInterval(fadeMovieClip, 100, garmentSlides_mc, 5);
      new Tween(categoryIndex_mc, "_y", null, 107, 412, 3, false);
      categoryIndex_mc.indexBack_mc.gotoAndStop("backToIndex");
      }
      //-----------------------------------\\


      //-----------Slideshow fades out, category index slides in, playhead jumps "please choose category" frame---------\\

      this.categoryIndex_mc.indexBack_mc.backToIndex_btn.onRelease = function ():Void {
      trace("button pressed");
      oIntervalIDs[garmentSlides_mc._name] = setInterval(fadeMovieClip, 0, garmentSlides_mc, 5);
      new Tween(categoryIndex_mc, "_y", null, 412, 107, 3, false);
      categoryIndex_mc.indexBack_mc.gotoAndStop("chooseText");
      }

      //-----------------------------------\\
        • 1. Re: onRelease function not working
          kglad Adobe Community Professional & MVP
          if "button pressed" doesn't appear, then you either have two or more onRelease handlers defined for your button (which i don't see) or you have an incorrect path/file name for this.categoryIndex_mc.indexBack_mc.backToIndex_btn.

          on the timeline that contains your onRelease code what's the following reveal:

          • 2. Re: onRelease function not working
            Seraya Level 1
            Thanks for the reply,

            The trace code revealed undefined in the output window.

            Maybe if I describe the setup a bit more it might help? backToIndex_btn is nested within indexBack_mc which in turn is nested within categoryIndex_mc. There's only 1 frame on the main timeline and it has 3 layers. Each of the layers contain a movieclip - intro_mc, categoryIndex_mc and garmentSlides_mc.

            intro_mc plays first with the first block of code listed above, then categoryIndex_mc fades in. When a button is pressed, garmentSlides_mc fades in and categoryIndex_mc slides down but still remains partially on the stage. When categoryIndex_mc reaches it's position, the playhead jumps to a frame in indexBack_mc which is where backToIndex_btn button is.

            So with this information, would you say the path/file name for this.categoryIndex_mc.indexBack_mc.backToIndex_btn is incorrect?
            • 3. Re: onRelease function not working
              kglad Adobe Community Professional & MVP
              well, there's a third possibility: your path/name may be correct but your btn may not exist (yet) on the frame that contains that code WHEN that code executes.

              on your btn's timeline, place the following to see if it's path/name is correctly listed in your code:

              • 4. Re: onRelease function not working
                Seraya Level 1
                After putting trace(this); on the button's timeline, the output window displayed:

                _level0.categoryIndex_mc.indexBack_mc

                What's the _level0 mean?
                • 5. Re: onRelease function not working
                  kglad Adobe Community Professional & MVP
                  _level0 is your main timeline. the main timeline contains your onRelease code, correct?

                  the trace(this) should be on the backToIndex_btn's timeline. retry.
                  • 6. Re: onRelease function not working
                    Seraya Level 1
                    I put the trace(this); on indexBack_mc timeline which is the timeline where backToIndex_btn sits. Apparently I can't put any code in the button itself so I put it on the timeline where it's placed. That's where I get the _level0.categoryIndex_mc.indexBack_mc in the output window.

                    Do you know what this means?
                    • 7. Re: onRelease function not working
                      kglad Adobe Community Professional & MVP
                      yes, it means your path/name is correct IF it's attached to a frame on the main (_level0) timeline AND your button instance name is correct.

                      are you certain your button exists when your code executes? ie, you can see it on-stage in the authoring environment no later than the frame that contains your code?
                      • 8. Re: onRelease function not working
                        Seraya Level 1
                        quote:

                        Originally posted by: kglad
                        yes, it means your path/name is correct IF it's attached to a frame on the main (_level0) timeline AND your button instance name is correct.

                        are you certain your button exists when your code executes? ie, you can see it on-stage in the authoring environment no later than the frame that contains your code?


                        I know that the following code causes the button to be on stage on frame 1 of the main timeline at the time it executes because it causes the playhead to jump to the frame label "backToIndex" within indexBack_mc which is where backToIndex_btn sits.

                        //-----------Slideshow fades in, category index slides out, playhead jumps "back to index" frame ---------\\

                        cat_btn.onRelease = function ():Void {
                        oIntervalIDs[garmentSlides_mc._name] = setInterval(fadeMovieClip, 100, garmentSlides_mc, 5);
                        new Tween(categoryIndex_mc, "_y", null, 107, 412, 3, false);
                        categoryIndex_mc.indexBack_mc.gotoAndStop("backToIndex");
                        }
                        //-----------------------------------\\

                        Then this code follows the previous code on frame 1 of the main timeline. The button is visible on the main timeline as explained above so when you ask "can you see it on-stage in the authoring environment no later than the frame that contains your code" doesn't that mean it is on stage becasue the code block before the code below causes it to be on stage?

                        //-----------Slideshow fades out, category index slides in, playhead jumps "please choose category" frame---------\\

                        this.categoryIndex_mc.indexBack_mc.backToIndex_btn.onRelease = function ():Void {
                        oIntervalIDs[garmentSlides_mc._name] = setInterval(fadeMovieClip, 0, garmentSlides_mc, 5);
                        new Tween(categoryIndex_mc, "_y", null, 412, 107, 3, false);
                        categoryIndex_mc.indexBack_mc.gotoAndStop("chooseText");
                        }

                        But if you mean that it should be on stage in a frame prior to the frame containing the code then no it's not on stage because there's only 1 frame on the main timeline.

                        So can you tell me what a workaround would be?

                        • 9. Re: onRelease function not working
                          kglad Adobe Community Professional & MVP
                          the answer to my question is no, your button is not on-stage in the authoring environment and therefore your button probably doesn't exist when the handler code executes.

                          to confirm, place the following:



                          • 10. Re: onRelease function not working
                            Seraya Level 1
                            After putting the code on the frame where the button is and also on the first frame of the main timeline where my onRelease handler code is, the first thing that appears in the output window is _level0 and then when I press the button it's _level0.categoryIndex_mc.indexBack_mc.

                            So how do I get around this?
                            • 11. Re: onRelease function not working
                              kglad Adobe Community Professional & MVP
                              don't put the code in your onRelease handler. put it just above or below your onRelease handler.
                              • 12. Re: onRelease function not working
                                Seraya Level 1
                                That's what I did. I put it above the the following code on the main timeline.

                                this.categoryIndex_mc.indexBack_mc.backToIndex_btn.onRelease = function ():Void {
                                oIntervalIDs[garmentSlides_mc._name] = setInterval(fadeMovieClip, 0, garmentSlides_mc, 5);
                                new Tween(categoryIndex_mc, "_y", null, 412, 107, 3, false);
                                categoryIndex_mc.indexBack_mc.gotoAndStop("chooseText");
                                }
                                • 13. Re: onRelease function not working
                                  kglad Adobe Community Professional & MVP
                                  you stated: "...then when I press the button it's _level0.categoryIndex_mc.indexBack_mc."

                                  that makes it appear one of your trace(this) statements is in a button handler. neither of the trace() functions should execute after a button is pressed.

                                  trace(this) on your main timeline should execute just about the time your button onRelease handler is defined and the other trace(this) should execute just as your button is instantiated.

                                  we can then determine if your code is executing before your button exists.
                                  • 14. Re: onRelease function not working
                                    Seraya Level 1
                                    Okay, I put trace(this); on the first frame of the timeline of indexBack_mc (which is the timeline that contains my button), and also on the main timeline just above the onRelease code. As soon as I test, the output window displays:

                                    _level0
                                    _level0.categoryIndex_mc.indexBack_mc
                                    • 15. Re: onRelease function not working
                                      kglad Adobe Community Professional & MVP
                                      so, now we know the problem. you're defining code for your button before it exists.

                                      there are many ways to resolve the problem. the easiest, without knowing your specifics, is to place your main timeline onRelease handler in a function that you call from the timeline that causes your 2nd trace (when you know your button exists).
                                      • 16. onRelease function not working
                                        Seraya Level 1
                                        Thanks,

                                        I've wrapped the code below in a function, and have then called the function categories() from the frame where backToIndex_btn sits like this: _level0.categories();:

                                        function categories ():Void {
                                        this.categoryIndex_mc.indexBack_mc.backToIndex_btn.onRelease = function ():Void {
                                        oIntervalIDs[garmentSlides_mc._name] = setInterval(fadeMovieClip, 10, garmentSlides_mc, -1);
                                        new Tween(categoryIndex_mc, "_y", null, 412, 107, 3, false);
                                        categoryIndex_mc.indexBack_mc.gotoAndStop("chooseText");
                                        }
                                        }

                                        This works but there's still just one problem. The fadeMovieClip function (as I showed in my first post) allows you to fade a movieclip up or down by having 1 for up or -1 for down. The 10 is the rate at which it fades, ie. faster or slower.

                                        When I test the code though, garmentSlides_mc fades out but at a really, really slow pace. I can hear my computer's processor speed up and the whole computer slows down. I don't know what the code is doing to eat up all the memory - it's really strange.

                                        When I use the first setInterval that causes categoryIndex_mc to fade in earlier on in the code, eg:

                                        oIntervalIDs[categoryIndex_mc._name] = setInterval(fadeMovieClip, 10, categoryIndex_mc, 1);

                                        ... it works fine, ie. it fades in at a fairly fast rate corresponding to the 10 in the above code. It also works fine the second time I use the setInterval that causes the garmentSlides_mc to fade in:

                                        cat_btn.onRelease = function ():Void {
                                        oIntervalIDs[garmentSlides_mc._name] = setInterval(fadeMovieClip, 10, garmentSlides_mc, 1);
                                        new Tween(categoryIndex_mc, "_y", null, 107, 412, 3, false);
                                        categoryIndex_mc.indexBack_mc.gotoAndStop("backToIndex");
                                        }

                                        But the third time I use it in the following code, that's when it fades out extremely slowly even though the rate is set to 10.

                                        function categories ():Void {
                                        this.categoryIndex_mc.indexBack_mc.backToIndex_btn.onRelease = function ():Void {
                                        oIntervalIDs[garmentSlides_mc._name] = setInterval(fadeMovieClip, 10, garmentSlides_mc, -1);
                                        new Tween(categoryIndex_mc, "_y", null, 412, 107, 3, false);
                                        categoryIndex_mc.indexBack_mc.gotoAndStop("chooseText");
                                        }
                                        }

                                        Do you know what could be causing this?
                                        • 17. Re: onRelease function not working
                                          kglad Adobe Community Professional & MVP
                                          you're probably not clearing your setInterval. add clearInterva(oIntervalIDs[garmentSlides_mc._name] ) just prior to your setInterval() statement and the problem in your fadeMovieClip() function.
                                          • 18. Re: onRelease function not working
                                            Seraya Level 1
                                            Yeah that did the trick - thanks so much for all your help.
                                            • 19. Re: onRelease function not working
                                              kglad Adobe Community Professional & MVP
                                              you're welcome.
                                              • 20. Re: onRelease function not working
                                                Seraya Level 1
                                                Hi,

                                                Sorry to come back to this topic. Could I just clarify one thing I don't understand? When I used those trace statements, ie. trace(this); and the output window displayed:

                                                _level0
                                                _level0.categoryIndex_mc.indexBack_mc

                                                Can you tell me why it dispayed _level0 instead of _root? I mean I thought that levels only came into play if you're loading external swfs or images into another swf. Can you explain?
                                                • 21. Re: onRelease function not working
                                                  kglad Adobe Community Professional & MVP
                                                  no, flash always traces the full absolute path of objects and _root is relative (to its level0).
                                                  • 22. Re: onRelease function not working
                                                    Seraya Level 1
                                                    okay thanks
                                                    • 23. Re: onRelease function not working
                                                      kglad Adobe Community Professional & MVP
                                                      you're welcome.

                                                      p.s. _level0 in the message just above should be _level.