A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: AS3 looping help

  1. #1
    Junior Member
    Join Date
    Jul 2011

    AS3 looping help

    This can't be too difficult but I can't seem to figure it out. Could someone please tell me how to loop this motion.
    I have added some action script to horizontally animate a strip of text... now I need that to loop so it's continuous.

    this is my code

    countries_mc.addEventListener(Event.ENTER_FRAME, fl_AnimateHorizontally);

    function fl_AnimateHorizontally(event:Event)
    countries_mc.x -= 2;



  2. #2
    i would just add the event listener to the current level..
    other than that, it should be moving countries_mc to the left 2 px every frame

  3. #3
    Senior Member
    Join Date
    Jun 2003
    Kent, WA
    emmalaunder, what do you mean by "loop"? Do you mean when it reaches the left side of the screen, it should move over to the right? If so, this would do it:

    countries_mc.addEventListener(Event.ENTER_FRAME, fl_AnimateHorizontally);
    function fl_AnimateHorizontally(event:Event)
       this.x -= 2;
       if (this.x < 0)
          this.x = stage.stageWidth;
    BTW I changed the reference within the enterFrame handler from "countries_mc" to "this". If you ever change the instance name or want to apply it to multiple movieclips, "this" will refer to the movieclip the code is operating on; you won't have to refactor anything.

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