15 Replies Latest reply on May 22, 2014 1:45 PM by kglad

    gotoandstop doesn't work in HTML5

    MartinPT Level 1

      I hope this is the right sub-community for this question.

       

      I am using Flash Professional CC Version 13.1.0.226 and have created a HTML5 project.

       

      I have created a movie clip (which in on the stage) called I_DistanceDownButton. It has 3 frames, each with a different coloured rectangle,  and each frame has the code this.stop();

       

      The movie (which currently consists of a single frame) has the following code:

       

      var v_name = "I_DistanceDownButton";

      var v_instance = this[v_name];

      v_instance.gotoAndStop(1); // 0 is the first frame in HTML5 ... but I have tried it with 2 as well.

      this.stop();

       

      However, when I publish it and run it, the MovieClip does not change. I know that it is getting the instance because if I change the 3rd line to ... v_instance.visible=false ... the clip hides.

       

      What am I missing?

        • 1. Re: gotoandstop doesn't work in HTML5
          kglad Adobe Community Professional & MVP

          createJS isn't going to be able to resolve this[v_name] into an object.

          1 person found this helpful
          • 2. Re: gotoandstop doesn't work in HTML5
            MartinPT Level 1

            createJS isn't going to be able to resolve this[v_name] into an object.

             

            If that is true then...

             

            a) Why does setting the visible to false work (as does setting the x value) and why, if I add an extra line of code, does ... v_instance.currentFrame ... return a value of 0 (since that is a MovieClip value)?

             

            b) What should I be using instead?

            • 3. Re: gotoandstop doesn't work in HTML5
              kglad Adobe Community Professional & MVP

              it doesn't work.

               

              it's just that nothing will appear stage with an erroneous reference, var v_instance = this[v_name];

               

              ie, add another shape to your stage and it won't appear either.

              • 4. Re: gotoandstop doesn't work in HTML5
                MartinPT Level 1

                I think you missed the line ... var v_name = "I_DistanceDownButton";

                 

                If v_name had not been set then you are correct that nothing would appear as it would be incorrect javascript. However, there are other items on the screen and ... as stated in my 2nd post ... if I replace ... v_instance.gotoAndStop(1) ... with ... v_instance.x=100 ... I see the 1st frame of the MovieClip and it moves to the correct location.

                • 5. Re: gotoandstop doesn't work in HTML5
                  kglad Adobe Community Professional & MVP

                  sorry.

                   

                  the problem is you need to link each variable to a timeline:

                   

                  this.v_name = "whatevername";

                  var v_instance = this[this.v_name];

                  1 person found this helpful
                  • 6. Re: gotoandstop doesn't work in HTML5
                    MartinPT Level 1

                    Again, you have missed part of my original post which states ... I am using Flash Professional CC Version 13.1.0.226

                    • 7. Re: gotoandstop doesn't work in HTML5
                      kglad Adobe Community Professional & MVP

                      sorry.

                       

                      the problem is you need to link each variable to a timeline:

                       

                      this.v_name = "whatevername";

                      var v_instance = this[this.v_name];

                      1 person found this helpful
                      • 8. Re: gotoandstop doesn't work in HTML5
                        MartinPT Level 1

                        That does not make any difference to me ... if it did work then var v_instance = this["whatevername"];would work and it doesn't (and also if the code could not understand the string without the extra 'this' for the string variable then why would anything be returned to the instance in my original code?). Did this change make a difference when you tried it?

                         

                        ---

                         

                        It looks to me that either gotoAndStop does not work, or it does work but the code that is being created by Adobe is incorrect in some way.

                         

                        I have even tried taking the source code that is produced and adding the line...

                         

                        this.I_DistanceDownButton.gotoAndStop(1)

                         

                        .. and that does not work either - and as ... this.I_DistanceDownButton ... is created by the call ... this.I_DistanceDownButton = new lib.M_DownMovie(); ... it should do.

                         

                        Has anyone any more ideas?

                        1 person found this helpful
                        • 9. Re: gotoandstop doesn't work in HTML5
                          kglad Adobe Community Professional & MVP

                          the code i suggested works.

                           

                          are you waiting until all frames of your movieclip load before executing the code i suggested?  ie, if you replace your goto with

                           

                          this.I_DistanceDownButton.gotoAndStop(1);

                           

                          does that work?  if not, you're not waiting until all frames of this.I_DistanceDownButton load.

                          • 10. Re: gotoandstop doesn't work in HTML5
                            MartinPT Level 1

                            I think I have found a solution.

                             

                            It looks as if for some reason the gotoAndStop code does not work on Frame 1 if placed in the timeline. If you call it as the result of an event (e.g. MouseDown) on frame 1, or if you extend the movie to 2 frames and put it on frame 2 it does work!

                             

                            Bizarre - but at least I can now code around the problem.

                            1 person found this helpful
                            • 11. Re: gotoandstop doesn't work in HTML5
                              kglad Adobe Community Professional & MVP

                              see message 9 for the explanation.

                               

                              and i don't think your code will work even when delayed.

                              • 12. Re: gotoandstop doesn't work in HTML5
                                MartinPT Level 1

                                My code has worked but your explanations shows why it is not quite as bizarre as I thought ... thanks for making sense of that.

                                 

                                For future reference, how do you wait until all frames of your movieclip load ... does the preloader code that you can find for a Flash SWF ave an equivalent for Flash Javascript (HTML5)?

                                • 13. Re: gotoandstop doesn't work in HTML5
                                  kglad Adobe Community Professional & MVP

                                  i use javascript code to ensure needed assets load.

                                  • 14. Re: gotoandstop doesn't work in HTML5
                                    heavyboots Level 2

                                    Kglad, if I can sort of interrupt here with a stupid question, how do you check to verify assets are loaded? Can it be done from within Flash CC?

                                     

                                    For example, I can't just put this.myInstance.gotoAndStop(1); this.stop(); in my JS frame script and expect it to execute like AS3 would.

                                     

                                    And if I put it in an on( "tick" ) event listener, it executes 24 times a second…

                                     

                                    Where is the happy middle ground?

                                     

                                    EDIT: Well, I see I can sort of get around this issue with:

                                     

                                    this.on( 'tick', doFrameEntered );

                                     

                                    function doFrameEntered( e ) {

                                         this.removeAllEventListeners();

                                         // do stuff that needs assets to be demonstrably populated onstage

                                    }

                                     

                                    but it still doesn't seem very elegant… :-/

                                    • 15. Re: gotoandstop doesn't work in HTML5
                                      kglad Adobe Community Professional & MVP

                                      i code that outside the flash pro ide.

                                       

                                      p.s.  you can remove that tick listener.