Skip navigation
Claunchster
Currently Being Moderated

Simple gotoAndStop Not Working . . . Stuck

Aug 6, 2012 2:38 PM

Tags: #problem #script #frame #as3 #cs5.5 #3.0 #3 #as3.0 #actionscript3 #function

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!

 
Replies
  • Currently Being Moderated
    Aug 6, 2012 2:45 PM   in reply to Claunchster

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

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 6, 2012 2:48 PM   in reply to Claunchster

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 6, 2012 4:20 PM   in reply to Claunchster

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 6, 2012 4:38 PM   in reply to Claunchster

    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);

              }

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 6, 2012 6:59 PM   in reply to Claunchster

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 6, 2012 7:09 PM   in reply to Claunchster

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 7, 2012 5:49 AM   in reply to Claunchster

    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-communi cation-oops-essence/ for more on how to create code that not only works now, but will be maintainable for the future.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points