A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: on enterframe makes the balls fly out in differant directions from the Stage center

Hybrid View

  1. #1
    Feeling adventurous? T1ger's Avatar
    Join Date
    Mar 2004
    Posts
    850
    I guess you have dragged 6 movieclips onto the stage and named them raj1 - raj6? Alternative to this is to create them dynamically. Right click on the MC in the library, and click "linkage", choose export for actionscript, and write "ball" in the identifier input field, then ok.

    then you can put this in first frame:
    PHP Code:
    stop();
    startX Stage.width/2//where the balls start, x-value
    startY Stage.height/2//where the balls start, y-value
    ballNum 6//this is how many balls we will have
    speed 2//the speed of the balls
    for (i=0;i<ballNum;i++) { //create the balls
        //attach the MC to the stage and store it temporary in the variable ball
        
    ball attachMovie("ball""ball"+ii); //(linkage name, new name ball0, ball1, etc, and depth i)
        //Put the ball in the middle of the stage
        
    ball._x startX;
        
    ball._y startY;
        
    //Make a random angle for each ball, in radians. Degrees goes from 0-360 degrees, radians is the same, it just goes from 0-2*PI, or 0-6.28.
        //Math.random() returns a number between 0 and 1.
        
    ball.angle Math.random()*Math.PI*2;
        
    //set the x and y-speed for this ball
        
    ball.xSpeed Math.cos(ball.angle);
        
    ball.ySpeed Math.sin(ball.angle);
    }
    this.onEnterFrame = function() {
        
    //loop through all balls
        
    for (i=0;i<ballNum;i++) {
            
    //put the ball in a temporary variable "ball"
            
    ball this["ball"+i];
            
    //add xspeed and yspeed to the _x and _y variable
            
    ball._x += ball.xSpeed;
            
    ball._y += ball.ySpeed;
        }

    Try to understand this, I have commented everything
    I don't have a photograph, but you can have my footprints. They're upstairs in my socks.

  2. #2
    Member
    Join Date
    Aug 2007
    Posts
    34

    Thanks for the help.

    Quote Originally Posted by T1ger
    I guess you have dragged 6 movieclips onto the stage and named them raj1 - raj6? Alternative to this is to create them dynamically. Right click on the MC in the library, and click "linkage", choose export for actionscript, and write "ball" in the identifier input field, then ok.

    then you can put this in first frame:
    PHP Code:
    stop();
    startX Stage.width/2//where the balls start, x-value
    startY Stage.height/2//where the balls start, y-value
    ballNum 6//this is how many balls we will have
    speed 2//the speed of the balls
    for (i=0;i<ballNum;i++) { //create the balls
        //attach the MC to the stage and store it temporary in the variable ball
        
    ball attachMovie("ball""ball"+ii); //(linkage name, new name ball0, ball1, etc, and depth i)
        //Put the ball in the middle of the stage
        
    ball._x startX;
        
    ball._y startY;
        
    //Make a random angle for each ball, in radians. Degrees goes from 0-360 degrees, radians is the same, it just goes from 0-2*PI, or 0-6.28.
        //Math.random() returns a number between 0 and 1.
        
    ball.angle Math.random()*Math.PI*2;
        
    //set the x and y-speed for this ball
        
    ball.xSpeed Math.cos(ball.angle);
        
    ball.ySpeed Math.sin(ball.angle);
    }
    this.onEnterFrame = function() {
        
    //loop through all balls
        
    for (i=0;i<ballNum;i++) {
            
    //put the ball in a temporary variable "ball"
            
    ball this["ball"+i];
            
    //add xspeed and yspeed to the _x and _y variable
            
    ball._x += ball.xSpeed;
            
    ball._y += ball.ySpeed;
        }

    Try to understand this, I have commented everything




    Hi T1ger

    this script works exectly i wanted to, Thakns once again for your help.


    do you suggest any book or any article on the net to developed the scripting skill

    Thanks once again!

    Regards.
    Praful.

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