11 Replies Latest reply on Aug 7, 2012 5:49 AM by Amy Blankenship

    Simple gotoAndStop Not Working . . . Stuck

    Claunchster Level 1

      I am in the process of making a desktop AIR application.  The predicament that I am having right now is that when I click on the delete button (in my app) I'm wanting it to delete the data (which it does) and then go back a frame which it won't. On frame 1 I have a login setup (not even trying to be secure by anymeans - just something simple to get the job done). On frame 2 I have everything else, which included logout btn, load btn, save btn, delete btn, and everything that the user needs to fill in. On frame 3 I have a delete check screen so when a user clicks on the delete button, it confirms that they want to actually delete their data.  When I click on "yes" it deletes, but then I can't get it to go back to frame 2. In frame 3 I deactivate all txt fields and btns on 2 and have a semi-transparent layer over everything.  My delete script is on frame 2.  I'm stuck and I'm sure I'm doing something stupid.  Any help would be great!

       

      Here is what I am using on Frame 2 to save, load and delete:

       

      var myso:SharedObject;
      btnSaveData.addEventListener(MouseEvent.CLICK,saveData);
      btnLoadData.addEventListener(MouseEvent.CLICK,retData);
        
      function saveData(event:MouseEvent):void
      {
                myso = SharedObject.getLocal("myname");
                if(con.mcBus127B.txtNames.text){
                          myso.data.val = con.mcBus127B.txtNames.text;
                          con.mcBus127B.txtNames.text = "";
                          status_txt.text = "Names Saved!";
                } else{
                          status_txt.text = "Nothing to Save!";
                }
                myso.close();
      }
      function retData(e:MouseEvent):void
      { 
                myso = SharedObject.getLocal("myname");
                if(myso.data.val){
                          con.mcBus127B.txtNames.text = myso.data.val;
                          status_txt.text = "Names Loaded!";
                } else{
                          status_txt.text = "Nothing to Load!";
                }
                myso.close();
      }
        function delData(e:MouseEvent):void
      {
                myso = SharedObject.getLocal("myname");
                if(myso.data.val){
                          delete myso.data.val;
                          con.mcBus127B.txtNames.text = "";
                          status_txt.text = "Names Cleared!";
                } else{
                          status_txt.text = "Nothing to Delete!";
                }
                myso.close();
      }
      function deleteData(event:MouseEvent):void
                {
                gotoAndStop(2);
                }
      
      

       

      On Frame three this is what I am using and it isn't working:

       

      btnDeleteData.addEventListener(MouseEvent.CLICK,delData);
      btnDeleteData.addEventListener(MouseEvent.MOUSE_OUT, deleteData);
      
      

       

      Well . . . my delData function works perfectly, its the deleteData where I'm trying to take it back to frame 2 that is an epic failure.

       

      Thanks Again!

        • 1. Re: Simple gotoAndStop Not Working . . . Stuck
          Ned Murphy Adobe Community Professional & MVP

          Put a trace in your deleteData function to see if it is executing when it should.

          • 2. Re: Simple gotoAndStop Not Working . . . Stuck
            Amy Blankenship Level 4

            This seems an odd way to do it. What if they mouse out before clicking? Try just calling deleteData with a numm parameter from delData.

            • 3. Re: Simple gotoAndStop Not Working . . . Stuck
              Claunchster Level 1

              Thanks for the info Amy, but I'm still pretty new to AS3, thus the sketchiness of my coding. What do you mean by trying to call deleteData from delData with a numm parameter?

               

              Claunchster

               

              "Do, or do not. There is no try." - Yoda

               

              Sent from my iPhone

              • 4. Re: Simple gotoAndStop Not Working . . . Stuck
                Amy Blankenship Level 4

                Sorry, that was a typo. It should have been "null" parameter. The reason behind that is that your current method signature expects an event, and if you called it from within delData, you could actually just pass on the same event, but it wouldn't be meaningful. Alternatively, you could change the method signature to not expect an event.

                • 5. Re: Simple gotoAndStop Not Working . . . Stuck
                  Ned Murphy Adobe Community Professional & MVP

                  DO.... as I mentioned, put a trace in the function to see if it is being called.  If it is, then keep using traces to track down what happens.  If it is not executing thetrace, then you know the button is not coded to call it.

                   

                  function deleteData(event:MouseEvent):void

                            {

                             trace("this function is being called");

                            gotoAndStop(2);

                            }

                  • 6. Re: Simple gotoAndStop Not Working . . . Stuck
                    Claunchster Level 1

                    Okay Ned, I've traced it and it is being called, but I have over 4000 lines of code doing a bunch of stuff.  I'm sure it's not the most elegant way of doing it, but I'm still a novice after piddling around for while with as3.  Do you have any tips for me on how I can trace down my other functions more expeditiously?

                    • 7. Re: Simple gotoAndStop Not Working . . . Stuck
                      Claunchster Level 1

                      So Amy, I called it withing delData to pass it on the same event as so:

                       

                       

                      function delData(e:MouseEvent):void
                      {
                                myso = SharedObject.getLocal("myname");
                                if(myso.data.val){
                                          delete myso.data.val;
                                          con.mcBus127B.txtNames.text = "";
                                          status_txt.text = "Names Cleared!"; 
                                } else{
                                          status_txt.text = "Nothing to Delete!";
                                }
                                myso.close();
                                gotoAndStop(2);
                      }
                      
                      

                       

                      It's not working, I probably didn't do that right . . .

                       

                      How could I change the method signature to not expect and event?

                      • 8. Re: Simple gotoAndStop Not Working . . . Stuck
                        Amy Blankenship Level 4

                        Instead of

                         

                        deleteData(e:MouseEvent)

                         

                        it becomes

                         

                        deleteData()

                         

                        because you'd no longer be using it as an event listener.

                         

                        If you have 4000 lines of code, there's a LOT more going on than what you've said (and you really should be using Class files, not timeline code at this point).

                         

                        One thought that has occurred to me is that maybe the gotoAndStop isn't actually being called on the MovieClip that has the frame 2 that you're thinking of? Can you tell a bit more about your file structure?

                         

                        Also, do you have strict mode on and a debug player installed? If you try to gotoAndStop(2) and there is no frame 2 on the MC that houses the gotoAndStop, you should be seeing an error.

                        • 9. Re: Simple gotoAndStop Not Working . . . Stuck
                          Ned Murphy Adobe Community Professional & MVP

                          You need to follow the trail and see where it takes you.  If that function is firing and it is executing the gotoAndStop(2) line, then you should put a trace in frame 2 and see if it traces after that trace from deleteData does. 

                           

                          Whether it does or not, you need to determine what other code might be active that could be forcing it to go elsewhere, essentially overriding the gotoAndStop command.

                           

                          You need to focus on functions that causes frame changes, possibly code in frame 2 that is run when you return to it.

                          • 10. Re: Simple gotoAndStop Not Working . . . Stuck
                            Claunchster Level 1

                            Amy, yeah I admit my fla is a little crazy with the coding, there's a lot of effects and flips to a bunch of stuff, but I think I nearly got it licked . . . nearly.  You two have definitely got me thinking in the right direction.  I have a movie clip exported for as (Delete_mc), that loads great and I am trying to call my delData function on the main from my Delete_mc, this is what I'm using in my Delete_mc:

                             

                             

                            btnDeleteData.addEventListener(MouseEvent.CLICK, deleteData);
                            function deleteData():void
                                      {
                                          Delete_mc(parent).delData();
                                          this.parent.removeChild(this);
                                      }
                            
                            

                             

                            When I just use the removeChild it works great but obviously doesn't call my delData function.  I'm sure it would be easier to set up a document class and define my function there, but I'm not that familiar with using classes yet (something on my AS3 todo list). Of course I'm not calling my function correctly from my movie clip Delete_mc, otherwise it'd be working . . . what am I doing wrong?

                            • 11. Re: Simple gotoAndStop Not Working . . . Stuck
                              Amy Blankenship Level 4

                              If the child mc is a Delete_mc, then casting its parent as Delete_mc will likely give you null (and should throw an error, but I don't know much about how Flash works with Strict turned off).

                               

                              Why not try something like this:

                               

                              In the child MC:

                               

                              btnDeleteData.addEventListener(MouseEvent.CLICK, deleteData);

                              //we're using this as an event handler again, so it now needs a parameter of the event

                              function deleteData(e:MouseEvent):void {

                                            dispatchEvent(new Event('DeleteData', true));//true makes it bubbling, so you can catch it anywhere above this MC

                              }

                               

                              On the root timeline in frame 3 (or whatever timeline contains the frames 2 and 3 in question)

                               

                              addEventListener('DeleteData', delData);

                               

                              function delData(e:Event):void {

                                      myso = SharedObject.getLocal("myname");

                                        if(myso.data.val){

                                                  delete myso.data.val;

                                                  con.mcBus127B.txtNames.text = "";

                                                  status_txt.text = "Names Cleared!";

                                        } else{

                                                  status_txt.text = "Nothing to Delete!";

                                        }

                                        myso.close();

                                        removeEventListener('DeleteData', delData);

                                        gotoAndStop(2);

                              }

                               

                              This is relatively well-structured code, where the View only has responsibility for notifying the "higher-ups" that something has happened that they need to do something about. Then the "higher-ups" can decide what, if anything, to do about the request. This will give you a good foundation for moving forward with a more loosely-coupled approach.  You may want to check out this website http://www.as3dp.com/2011/04/beginners-actionscript-3-0-object-communication-oops-essence/ for more on how to create code that not only works now, but will be maintainable for the future.