10 Replies Latest reply on Mar 16, 2016 10:20 AM by adumi

    In Canvas, navigate the timeline of an object on the stage without mouse action

    adumi Level 1

      For some reason, in Canvas, this will not work:

      this.myObject.gotoAndStop(1);
      
      

       

      Whereas this, when mouse is clicked, will:

      this.test.addEventListener("click", fl_ClickToGoToAndStopAtFrame_1.bind(this));
      function fl_ClickToGoToAndStopAtFrame_1()
      {
        this.myObject.gotoAndStop(1);
      }
      
      

      I`m new to canvas, What am I missing here, please?

        • 1. Re: In Canvas, navigate the timeline of an object on the stage without mouse action
          Colin Holgate MVP & Adobe Community Professional

          The object you're trying to change doesn't yet exist when the script runs. Try putting the script on the second frame where the object is in the timeline. Or use a "tick" listener to make the change happen on the next enter frame.

          • 2. Re: In Canvas, navigate the timeline of an object on the stage without mouse action
            adumi Level 1

            Thank you, Colin! I put the code on second frame of the main timeline and it did work, but then I get the first frame of the object which I am manipulating flashing for a brief moment before it settles finally on the desired frame, which is quite disturbing, of course.  I tried putting the following lines on the first frame of the main time line:

            this addEventListener(Event.ENTER_FRAME, myFunction);
            function myFunction(e:Event){
            this.myObject.gotoAndStop(1);
            }
            
            
            
            

            No matter if I have only a single frame on the timeline or two, that would not work.

            • 3. Re: In Canvas, navigate the timeline of an object on the stage without mouse action
              ClayUUID Adobe Community Professional

              If you don't want the first frame to show ever, put this.gotoAndStop(1); on the first frame of the clip itself.

              • 4. Re: In Canvas, navigate the timeline of an object on the stage without mouse action
                adumi Level 1

                Thank you, Clay`s! This DID work, But suppose, as is my case, that I have on stage more than a single instance of the same clip/object, and I want to control each differently? Meaning that when the canvas loads I want the first instance to gotoAndStop to it`s first frame, the second to the second frame and so forth. In AS3 I can control them externally via their instance names. Is there no simple way for one timeline to control another`s navigation upon the canvas loading for the first time?

                • 5. Re: In Canvas, navigate the timeline of an object on the stage without mouse action
                  ClayUUID Adobe Community Professional

                  Of course you can control clips that way. You did it yourself just two posts ago. You just have to figure out your own solution within the known limitation that you can't externally control a script within the first frame that it's on the stage.

                  • 6. Re: In Canvas, navigate the timeline of an object on the stage without mouse action
                    Colin Holgate MVP & Adobe Community Professional

                    A cheat way to do things would be to use a global variable. If the symbol had this script:

                     

                    this.gotoAndStop(f++);

                     

                    and in frame 1 of the timeline you had:

                     

                    f = 0;

                     

                    all of the instances of the same object would go to the next value of f.

                    • 7. Re: In Canvas, navigate the timeline of an object on the stage without mouse action
                      adumi Level 1

                      Thank you, Clay`s! So basically If I DO want, on the first frame of the main timeline, to control externally the navigation of an instance on stage, and I don`t want that instance`s first frame to show (Even if for a blinking half a second ) until this instance gets the external command to go to another frame, my only choice is to leave blank the first frame of that instance? Of course I could do that, but naturally, clips that have their first frame - blank, empty, are much harder to place and manipulate on stage in the authoring environment as they`re almost invisible there.

                      • 8. Re: In Canvas, navigate the timeline of an object on the stage without mouse action
                        adumi Level 1

                        Thank you, Colin! Globals sound like a good way to go but it still does not solve the main problem - I do not want the instances of the same clip to behave the same, otherwise I could put the code in the clip and they would act the same. I want each instance to act differently.  Could I for example put in the clip that I want to control a variable that pertains only to it, for example var f and then inside this clip

                        gotoandStop(f);
                        
                        
                        
                        
                        
                        

                        and then on the main timeline of the first frame put something such as:

                        this.instance1.f = 1;
                        this.instance2.f = 2;
                        
                        
                        
                        
                        
                        

                         

                        or instead do it with some function inside the clip that I could control from outside of it only per instance?

                        • 9. Re: In Canvas, navigate the timeline of an object on the stage without mouse action
                          ClayUUID Adobe Community Professional

                          adumi wrote:

                           

                          So basically If I DO want, on the first frame of the main timeline, to control externally the navigation of an instance on stage...

                           

                          Uh... no. We've already established that you can't externally control a clip during the first frame it's on the stage, no matter how much you want to. What you can do is have each clip hide itself during its first frame (either by this.gotoAndStop(1), where frame 1 is blank, or by this.visible = false), then on any frame after that you can start issuing external gotos.

                           

                          Or if you really, REALLY can't have that one-frame delay to get everything set up, you could go with what Colin suggested and communicate with each clip via external variables. They wouldn't even have to be global. Like declare this.clip1Frame = 5; then in the clip have this.gotoAndStop(this.parent.clip1Frame);

                           

                          Okay, I just did some experimenting, and it seems the real problem here is that the timeline instance on subclips doesn't get immediately initialized. The clip container itself, however, does exist, which means you can set variables on it. So doing this.myclip.goFrame = 1; in the parent, then this.gotoAndStop(this.goFrame); in the subclip, works.

                          • 10. Re: In Canvas, navigate the timeline of an object on the stage without mouse action
                            adumi Level 1

                            Thank you, Clay`s! That is simply Awesome!!!  And thank you, Colin, so much, too! Despite this being solved without globals I`ll definitely use them as various instances control others in my project time and again, and so, on the way I learned from you, Colin, how to declare them (much simpler than AS3, btw)  Thank you so much to both! So happy here!