dcsimg
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [F8] animating with actionscript

Hybrid View

  1. #1
    Member
    Join Date
    Oct 2001
    Posts
    37

    [F8] animating with actionscript

    I'm working on an animation. The 'red balls' enter, breaks up and bounces around the stage. What I want to do is to have all those balls stop (when the user clicks) and move to the center of the stage. I was wondering if it was possible to do this using actionscript? The red balls are coded to move around randomly.

    Here's the SWF file:
    Animation SWF

    So right now, when you click, the balls just stop...but I know if I enter

    this._X = 400;
    this._Y = 300;

    in the onClipEvent (mouseUp) part of my code, all the balls will be placed in the center. So I was wondering if there a way to have the balls stop and actually have them all MOVE towards the center?

    Each ball is a movie clip and I'm using this code to control all the balls:

    Code:
       onClipEvent (load) {
    
        	speed = 25;
        	angle = random(360);
        	speedX = Math.cos(angle*Math.PI/180)*speed;
        	speedY = Math.sin(angle*Math.PI/180)*speed;
    
        }
    
        onClipEvent (enterFrame) {
       	
            this._X += speedX;
        	this._y += speedY;
    
        	if (this._X>=760) {
        		speedX = -speedX;
    
    
        	} else if (this._X<=15) {
        		speedX = -speedX;
    
    
        	} if (this._Y>=560) {
        		speedY = -speedY;
    
    
        	} else if (this._Y<=15) {
        		speedY = -speedY;
    
        	}
    
        }
    
        onClipEvent (mouseUp) {
    
        	speed = 0; 
        	angle = 0; 
        	speedX = 0;
        	speedY = 0;
    
        }


    Hope I explained my problem clearly!
    Thanks.

  2. #2
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    can you post your .fla with the balls and this code only?.. Im sure it will only be a few tweaks..

    maybe on mouse down you delete the current enterFrame actions..and run another one.. stating what positions you need the balls to go to.I whipped this up.. I messed with the area constraints..but you dont have to...

    see if this works for you:
    Code:
    onClipEvent (load) {
        speed = 25;
        angle = random(360);
        speedX = Math.cos(angle*Math.PI/180)*speed;
        speedY = Math.sin(angle*Math.PI/180)*speed;
    }
    
    onClipEvent (enterFrame) {
       	if(centerMode != true) {
            this._X += speedX;
        	this._y += speedY;
        	if (this._X >= (Stage.width - this._height/2)) {
        		speedX = -speedX;
        	} else if (this._X <= (0 + this._height/2)) {
        		speedX = -speedX;
        	} if (this._Y >= (Stage.height - this._height/2)) {
        		speedY = -speedY;
        	} else if (this._Y <= (0 + this._height/2)) {
        		speedY = -speedY;
        	}
    	}else if (centerMode == true) {
    			this._x -= (this._x - _root.goTo_x)/6;
    			this._y -= (this._y - _root.goTo_y)/6;
    	} 
    }
    
    onClipEvent (mouseUp) {
    	centerMode = true;
    	_root.goTo_x = 300;
    	_root.goTo_y = 400;
    	/*
    	speed = 0; 
        angle = 0; 
        speedX = 0;
        speedY = 0;
    	*/
    }

  3. #3
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    hi..here is a second revision I did... using two buttons to control the sopping and starting of the 'bounce' animation:

    Code:
    onClipEvent (load) {
        speed = 25;
        angle = random(360);
    	_root.centerMode = false;
        speedX = Math.cos(angle*Math.PI/180)*speed;
        speedY = Math.sin(angle*Math.PI/180)*speed;
    }
    
    onClipEvent (enterFrame) {
       	if(_root.centerMode == false) {
            this._x += speedX;
        	this._y += speedY;
        	if (this._x >= (Stage.width - this._height/2)) {
        		speedX = -speedX;
        	} else if (this._x <= (0 + this._height/2)) {
        		speedX = -speedX;
        	} if (this._y >= (Stage.height - this._height/2)) {
        		speedY = -speedY;
        	} else if (this._y <= (0 + this._height/2)) {
        		speedY = -speedY;
        	}
    	}else if(_root.centerMode == true) {
    			this._x -= (this._x - _root.goTo_x)/6;
    			this._y -= (this._y - _root.goTo_y)/6;
    	} 
    }
    
    /*onClipEvent (mouseUp) {
    	centerMode = true;
    	_root.goTo_x = 300;
    	_root.goTo_y = 400;
    	
    	speed = 0; 
        angle = 0; 
        speedX = 0;
        speedY = 0;
    	
    }*/
    and of the two buttons I have this code:
    Code:
    on (press) {
    	_root.centerMode = false;
    }
    and
    Code:
    on (press) {
    	_root.centerMode = true;
    	_root.goTo_x = Stage.width/2;
    	_root.goTo_y = Stage.height/2;
    	/*
    	_root.goTo_x = 300;
    	_root.goTo_y = 400;
    	*/
    }
    this way you can stop and start it whenever.. (I just moved it to a button event for testing purposes)

  4. #4
    Member
    Join Date
    Oct 2001
    Posts
    37
    thanks a lot, whispers! Got it to work now.

    Here's the result:
    SWF

    If you still want to see the fla:
    FLA

    And I have an .AS file for the code:
    AS file

  5. #5
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    glad it all worked out!!

    can I ask what this will be for? Or just an experiment?

    Would be cool if on another click they started to move around again..

  6. #6
    Member
    Join Date
    Oct 2001
    Posts
    37
    It's for a presentation. I'm just creating an interactive diagram/chart to show how a company I work for is structured. The red balls represent individuals that make up the company. (Corny i know) The part you saw is just the intro animation.

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