A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: How to continuously spawn movieclips?

  1. #1
    Senior Member
    Join Date
    Jan 2008
    Posts
    107

    How to continuously spawn movieclips?

    Hey all.

    I'm wondering how could I write a function that spawns movieclips from all sides of the stage, just like Squares 2? Is it by using a sort of loop?

    Thanks.

  2. #2
    Junior Member
    Join Date
    Jun 2009
    Posts
    6
    Quote Originally Posted by Hurdarr View Post
    Hey all.

    I'm wondering how could I write a function that spawns movieclips from all sides of the stage, just like Squares 2? Is it by using a sort of loop?

    Thanks.
    There are several ways of doing this. This simplest is not to use any coding at all, but to simply create a looping movieclip that sends things across the stage.


    If you do want to use code, then the answer is more complicated (but your filesize will be smaller). You would want to set things on stage with code similar to this (be sure to set the linkage class name and export the MC for actionscript or this won't work):
    var varibleName:MovieClip = linkageNameOfMCinLibrary();
    stage.addChild(variableName);

    From there, you can set x and y values, and dynamically tween them to race across the stage.
    If you don't know about AS3 tweens, use something like this:
    var myTween:Tween = new Tween(movieClip,"x",Strong.easeIn,-50,600,35,false);
    myTween.start();

    To have this continually happening, use a timer event:
    // We need to import the utils package
    import flash.utils.*;

    // Create a new Timer object with a delay of 500 ms
    var myTimer:Timer = new Timer(500);
    myTimer.addEventListener(”timer”, timedFunction);

    // Start the timer
    myTimer.start();

    This will call "timedFunction" every 500 milliseconds. You'd probably want to set this to something closer to 50. Depending on what you want, you could have that function call one item from each of the four directions, randomly, or whatever you'd like.

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