A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Continuous Random Animations

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    10

    Continuous Random Animations

    I just want to create sparkling stars at random. I can place the twinkling star to one random location but that is fixed while i close the window. I want to place the star at different random locations in the same window. I googled and i found action script code but that dosnt useful for a movieclip animation.
    code:
    onClipEvent(enterFrame)
    {
    _x=_x=random(250);
    _y=_y=random(250);
    }
    by this actionscript to the movie clip, I can executes continuously but it is very fast one.
    code:
    onClipEvent(load){
    _x= random(200);
    _y= random(200);
    }
    this choses random location but the location is static while i close the window.


    I want to Place the movieclip at different location just after finishing of the previous one. How to do that one?
    Attached Files Attached Files

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    onClipEvent (load) {
            _x = _x = random(180);
            _y = _y = random(400);
            _alpha = 80 + random(20);
            _xscale = _yscale = 80 + random(80);
            ct = random(100);
    }
    onClipEvent (enterFrame) {
            if (ct <= 0) {
                    if (_alpha <= 0) {
                            _x = random(180);
                            _y = random(400);
                            _alpha = 80 + random(20);
                            _xscale = _yscale = 80 + random(80);
                            ct = 50 + random(50);
                    } else {
                            _alpha = _alpha - 2;
                    }
            } else {
                    ct = ct - 1;
            }
    }

  3. #3
    Junior Member
    Join Date
    Nov 2013
    Posts
    10

    Random number of selections

    Thank You very much for that code. Now only I understand a little bit about onClipEvent. I was tried to make a starry night using the same movieclip. i succeeded a little bit. But I am not satisfied. I just make duplicates of my movie clip 50 times and places thats at random positions by this code.
    code::
    for(var i=1;i<=50;i++){
    newname = "star1"+i;
    star1.duplicateMovieClip(newname,i);
    newname._x = random(750);
    newname._y = random(550);
    }
    star1 is my instance name in properties. I got 50 stars at random positions when i set actionscript code as
    onClipEvent(load){
    _x= random(800);
    _y= random(600);
    _alpha = 100;
    }
    onClipEvent(enterFrame)
    {
    if(_alpha<=0){
    _x = random(700);
    _y = random(599);
    _alpha = 100;
    }
    else {
    _alpha--;
    }
    }
    all stars just dimmed slowly and disperses, then a new set of stars appears. But all the 50 stars starts and disperses at the same time.
    I want to chose some of stars at random to start at beginning, before finishing of the movieclip the second set is to be started. How to set such a condition and where to set. pls refer the attached file.
    Attached Files Attached Files

  4. #4
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    // place on main timeline, delete existing onClipEvent codes
    var tID;
    var numStars = 50;
    var stars = [];
    
    star1.onEnterFrame = function() {
            if (random(50) == 0) {
                    mc = stars[random(stars.length - 1)];
                    mc._x = random(550);
                    mc._y = random(400);
                    mc._alpha = random(90);
            }
    };
    
    makeStar();
    
    function makeStar() {
            var mc = star1.duplicateMovieClip("s" + numStars, numStars--);
            mc._x = random(550);
            mc._y = random(400);
            mc._alpha = random(90);
            stars.push(mc);
            if (numStars > 1) {
                    tID = setTimeout(makeStar, random(53));
            } else {
                    clearTimeout(tID);
            }
    }

  5. #5
    Junior Member
    Join Date
    Nov 2013
    Posts
    10
    yep the code works perfect but i am unable to find meaning of these codes. Actually what these code does? Can you please explain a little bit how it is executed?

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