A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [RESOLVED] Get stuff to stop when using ENTER_FRAME

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    10

    resolved [RESOLVED] Get stuff to stop when using ENTER_FRAME

    Hello all. I'm sure that there's an easy answer for this.

    I have a one-frame .fla with script on one layer and a movie clip on another. The movie clip has an instance name of "titleBar," which moves from left to right using dynamic tweening. The tween code moves it from an X position of 200 to a X position of 820.

    Then I have a function called "xChange," which waits for titleBar's X value to be 820. Once it does, I'd eventually want to load an external swf but I'm just running a trace for now.

    The function works but it keeps running over and over again. I'd like it stop after it runs just once. Any idea?

    Again, I'm sure it's easy...thanx in advance! Here's the code.

    Code:
    import fl.transitions.Tween;
    import fl.transitions.easing.*;
    
    
    var ptPanelHome:Point=new Point(200,0);
    
    titleBar.x=ptPanelHome.x;
    titleBar.y=ptPanelHome.y;
    var twSlide:Tween;
    twSlide=new Tween(titleBar,"x",Back.easeOut,ptPanelHome.x,ptPanelHome.x+620,20);
    
    addEventListener(Event.ENTER_FRAME, xChange);
    function xChange(evt:Event):void {
    	if (titleBar.x==820) {
    		trace("ta-da!!!!!!!!");
    	}
    }

  2. #2
    Senior Member
    Join Date
    Jan 2010
    Location
    England
    Posts
    268
    wouldnt it be something like
    if (titlebar._x == 820) {
    stop();
    }
    }


    that probably wont work..but if your trying to have it play a "you win" page or something when it hits that X position you could have it go to a different frame with the gotoandplay action and then use a stop action.

    not sure if this will help you but good luck with your project all the same.

  3. #3
    Junior Member
    Join Date
    Feb 2010
    Posts
    10
    Hi steve...thanx for the response!

    I wish that was the solution. But I did things in AS3 which deprecates "_x", so it no longer works. I did throw a stop() command in there just for the heck of it, but sadly had no luck there.

    I definitely could have things go to another frame or even run a separate two-frame MC with no stop() action and just loops and looks for the value of my variable. But as AS3 is a full-on object oriented programming language, there's a chance that I can keep things in one frame.

    Again, thanx for the response!

  4. #4
    mentally unstable member smayer72's Avatar
    Join Date
    Jan 2001
    Posts
    527
    Give this a go. I haven't tried it but may do the job. If not post the fla for a quick look.

    Code:
    addEventListener(Event.ENTER_FRAME, xChange);
    function xChange(evt:Event):void {
    	if (titleBar.x==820) {
    		removeEventListener(Event.ENTER_FRAME, xChange);
                             stop();
    	}
    }
    Scott (Australia)

    Sarcasm, chaos and disorder. My work here is done!

    **Mark you threads as [RESOLVED] please.**

  5. #5
    Junior Member
    Join Date
    Feb 2010
    Posts
    10
    smayer72:

    That did it! Thank you VERY much for your help here...greatly appreciated!!!

    Final working code is below:

    Code:
    import fl.transitions.Tween;
    import fl.transitions.easing.*;
    
    
    var ptPanelHome:Point=new Point(200,0);
    
    titleBar.x=ptPanelHome.x;
    titleBar.y=ptPanelHome.y;
    var twSlide:Tween;
    twSlide=new Tween(titleBar,"x",Back.easeOut,ptPanelHome.x,ptPanelHome.x+620,20);
    
    addEventListener(Event.ENTER_FRAME, xChange);
    function xChange(evt:Event):void {
           if (titleBar.x==820) {
                   removeEventListener(Event.ENTER_FRAME, xChange);
                            stop();
           }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center